Task

Write a    for    loop which writes a countdown from   10   to   0.



Related tasks

   Loop over multiple arrays simultaneously
   Loops/Break
   Loops/Continue
   Loops/Do-while
   Loops/Downward for
   Loops/For
   Loops/For with a specified step
   Loops/Foreach
   Loops/Increment loop index within loop body
   Loops/Infinite
   Loops/N plus one half
   Loops/Nested
   Loops/While
   Loops/with multiple ranges
   Loops/Wrong ranges


*        Loops/Downward for        27/07/2015
LOOPDOWN CSECT                    
         USING  LOOPDOWN,R12
         LR     R12,R15            set base register
BEGIN    EQU    *
*        fisrt loop with a BXLE    BXLE: Branch on indeX Low or Equal
         LH     R2,=H'11'          from 10 (R2=11) index
         LH     R4,=H'-1'          step -1 (R4=-1)
         LH     R5,=H'-1'          to 0    (R5=-1)
LOOPI    BXLE   R2,R4,ELOOPI       R2=R2+R4 if R2<=R5 goto ELOOPI
         XDECO  R2,BUFFER          edit R2
         XPRNT  BUFFER,L'BUFFER    print    
         B      LOOPI
ELOOPI   EQU    *
*        second loop with a BCT    BCT: Branch on CounT
         LA     R2,10              index   R2=10
         LA     R3,11              counter R3=11
LOOPJ    XDECO  R2,BUFFER          edit R2
         XPRNT  BUFFER,L'BUFFER    print
         BCTR   R2,0               R2=R2-1
ELOOPJ   BCT    R3,LOOPJ           R3=R3-1 if R3<>0 goto LOOPI
RETURN   XR     R15,R15            set return code
         BR     R14                return to caller
BUFFER   DC     CL80' '
         YREGS  
         END    LOOPDOWN