Chapter 4 Optimization
52 Usage Example
Optimization of branches
For unconditional branch instructions, a JMP label instruction is replaced by a BRA label instruction if
the jump target is within the range available for the shorter, relative branch instruction BRA. Similarly,
a CALL label, CALLS label, or JSR label instruction is replaced by the shorter version with a 16-bit
displacement (d16,PC) instead of the one with the 32-bit displacement (d32,PC).
The following table shows the possibilities for optimizing the unconditional branch instructions and the
subroutine call instructions.
Table 4-8 Substituted Instructions For Out-Of Range Conditional Branch Instructions
Source Instruction Candidate instruction 1 Candidate instruction 2 Candidate instruction 3
BLT LABEL BRA LABEL BGE *+5
JMP LABEL
BGE *+7
JMP LABEL
BGT LABEL BGT LABEL BLE *+5
JMP LABEL
BLE *+7
JMP LABEL
BGE LABEL BGE LABEL BLT *+5
JMP LABEL
BLT *+7
JMP LABEL
BLE LABEL BLE LABEL BGT * +5
JMP LABEL
BGT *+7
JMP LABEL
BCS LABEL BCS LABEL BCC *+5
JMP LABEL
BCC *+7
JMP LABEL
BHI LABEL BHI LABEL BLS *+5
JMP LABEL
BLS *+7
JMP LABEL
BCC LABEL BCC LABEL BCS *+5
JMP LABEL
BCS *+7
JMP LABEL
BLS LABEL BLS LABEL BHI *+5
JMP LABEL
BHI *+7
JMP LABEL
BEQ LABEL BEQ LABEL BNE *+5
JMP LABEL
BNE *+7
JMP LABEL
BNE LABEL BNE LABEL BEQ *+5
JMP LABEL
BEQ *+7
JMP LABEL
BVC LABEL BVC LABEL BVS *+6
JMP LABEL
BVS *+8
JMP LABEL
BVS LABEL BVS LABEL BVC *+6
JMP LABEL
BVC *+8
JMP LABEL
BNC LABEL BNC LABEL BNS *+6
JMP LABEL
BNS *+8
JMP LABEL
BNS LABEL BNS LABEL BNC *+6
JMP LABEL
BNC *+8
JMP LABEL
Table 4-9 Optimization of branches
Source Instruction First Candidate Second Candidate Third Candidate
BRA label BRA label JMP label JMP label
JMP label BRA label JMP label JMP label
CALL label CALL label CALL label
CALLS label CALLS label CALLS label
JSR label JSR label JSR label