Skip to main content

25 Far Branches

When a conditional branch cannot reach a destination, the assembler will replace these with far branches which use the longer offset available to unconditional jumps to reach the destination. This is done by inserting a short branch with inverted conditions past an unconditional jump. For example:

target:
bne a0, a1, target
.rep 1024
nop
.endr
bne a0, a1, target

This example uses a series of nops to separate the final instruction from the branch target target such that the second bne instruction cannot reach it with its offset. As such a unconditional branch to the target is added and the original instruction replaced with a conditional branch with inverted conditions to jump over this new instruction. Consequently, the final assembled binary contains the following:

0: 00b51063 bne a0,a1,0 \<target>
...
1004: 00b50463 beq a0,a1,100c \<target+0x100c>
1008: ff9fe06f j 0 \<target>