Jump to content

Flow-control structures: Difference between revisions

Line 14:
*   [[Iteration|Loop Structures]]
<br><br>
 
=={{header|360 Assembly}}==
Common 360 opcodes for flow-control structures:
===Unconditional Branch (B)===
To perform a 'goto'.
<lang 360asm>
B TESTPX goto label TESTPX
BR 14 goto to the address found in register 14
</lang>
===Branch and Link (BAL)===
To perform a 'call' to a subroutine. The first register (14 in the example) at execution time is the next sequential address to allow a 'return'.
<lang 360asm>
BAL 14,SINUSX call SINUSX
BALR 14,15 call the subroutine at the address found in register 15
</lang>
===Conditional Branch (BC)===
Fistly a compare instruction set the condition code (cc), secondly a conditional branch is performed.
<lang 360asm>
L 4,A Load A in register 4
C 4,B Compare A with B
BH TESTGT Branch on High if A>B then goto TESTGT
BL TESTLT Branch on Low if A<B then goto TESTLT
BE TESTEQ Branch on Equal if A=B then goto TESTEQ
BNH TESTLE Branch on Not High if A<=B then goto TESTLE
BNL TESTGE Branch on Not Low if A>=B then goto TESTGE
BNE TESTNE Branch on Not Equal if A<>B then goto TESTNE
</lang>
===Branch on Count (BCT)===
To perform unconditional loops.
<lang 360asm>
LA 3,8 r3 loop counter
LOOP EQU *
... loop 8 times (r3=8,7,...,2,1)
BCT 3,LOOP r3=r3-1 ; if r3<>0 then loop
</lang>
===Branch on Index (BX.)===
BXLE to perform loops in old Fortran style with 3 registers.
<lang 360asm>
* do i=1 to 8 by 2
L 3,1 r3 index and start value 1
LA 4,2 r4 step 2
L 5,8 r5 to value 8
LOOPI EQU *
... loop 4 times (r3=1,3,5,7)
BXLE 3,4,LOOPI r3=r3+r4; if r3<=r5 then loop
</lang>
BXH to perform backward loops with 3 registers.
<lang 360asm>
* do i=8 to 1 by -2
L 3,1 r3 index and start value 8
LH 4,=H'-2' r4 step -2
L 5,8 r5 to value 1
LOOPI EQU *
... loop 4 times (r3=8,6,4,2)
BXH 3,4,LOOPI r3=r3+r4; if r3>r5 then loop
</lang>
 
 
=={{header|6502 Assembly}}==
Line 36 ⟶ 93:
The return from interrupt instruction pops the flags off the stack, pops the return address off the stack, adds one, and jumps to that location:
<lang 6502asm> RTI ;ReTurn from Interrupt</lang>
 
=={{header|Ada}}==
 
1,392

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.