Most of the time we are happy using the BCR and BC instructions for our branching. There are a few others which are sometimes useful.
There are actually a few more branch instructions such as BXLE and BXH which are not covered here.
Branch and Link (BAL)
BAL is normally used to transfer control to an internal subroutine.
The syntax for it looks like this:
BAL R,D(X,B)
When this is executed, there are two steps involved:
The second half of the PSW contains (in bits 41-64) the address of the next instruction, that is, the instruction immediately after the BAL. As we normally use 24-bit addresses in ASSIST, only bits 41-64 are used as the address. This means that at the end of the internal subroutine, we can use
BR R
to go back to the main routine.
BAL is a type RX instruction.
Branch and Link Register (BALR)
BALR is normally used to transfer control to an external subroutine.
BALR is very much like BAL except that the address involved is taken from a register.
The syntax for it looks like this:
BALR R1,R2
When this is executed, there are two steps involved:
As with BAL, the new value in R1 provides a way to return after the subroutine call. We can use
BR R1
to go back to the main routine.
Notice that
BALR 7,0
will simply load the second half of the PSW into register 7.
BALR is a type RR instruction.
Branch on Count (BCT)
BCT is intended for use in counted loops, specifically in situations in which we want to count down from a positive value to 0.
The syntax for it looks like this:
BCT R,D(X,B)
When this is executed, there are two steps involved:
BCT is a type RX instruction.
Branch on Count Register (BCTR)
BCTR is very much like BCT except that the address involved is taken from a register.
The syntax for it looks like this:
BCTR R1,R2
When this is executed, there are two steps involved:
The most common use of BCTR is to decrement a register by 1, as in:
BCTR 5,0
The value is register 5 is decreased by 1 and no branch is taken because the second register is 0.