7. Branch Instruction

These instructions cause execution to jump to the target location usually specified by the label (see the label assembly instruction). Conditional branch and it and ite instruction test application Status register (APSR), N (negative), Z (zero), C (carry), and V (overflow) flags to determine whether the branch should be performed.

Most public assembler instructions (including move operations) will set flags, but there are clear comparison instructions to allow test values.

For more details on the meaning of condition flags, see the chapter describing the comparison function.

7.1. File Specification

Symbol: Rm means ARM register R0-R15. LABEL means the label defined by the label() assembly instruction. <condition> means one of the following condition specifiers:

  • eq Equal (result is 0)
  • ne not equal
  • cs Set Carry
  • cc Clear Carry
  • mi negative
  • pl Positive
  • vs Set Overflow
  • vc Clear Overflow
  • hi > (Unsigned comparison)
  • ls <= (Unsigned comparison)
  • ge >= (Signed comparison)
  • lt < (Signed comparison)
  • gt > (Signed comparison)
  • le <= (Signed comparison)

7.2. Transfer Tab

  • b(LABEL) Unconditional transfer
  • beq(LABEL) Transfer if equal
  • bne(LABEL) Transfer if not equal
  • bge(LABEL) If greater than or equal to transfer
  • bgt(LABEL) If greater than transfer
  • blt(LABEL) If less than, transfer(<)(signed)
  • ble(LABEL) If less than or equal to transfer(<=)(signed)
  • bcs(LABEL) Transfer if carry flag is set
  • bcc(LABEL) Transfer if clear carry flag
  • bmi(LABEL) If negative, transfer
  • bpl(LABEL) If it is a regular transfer
  • bvs(LABEL) If the overflow flag is set, transfer
  • bvc(LABEL) Transfer if clear overflow flag
  • bhi(LABEL) If above, transfer (unsigned)
  • bls(LABEL) Transfer if below or equal (unsigned)

7.3. Long branch

The code generated by the transfer instructions listed above uses a fixed bit width to specify the PC-related transfer target. Therefore, an a long procedure where the branch instruction is far from its target, the assembler will produce a “branch not in range” error.This can be overcome by variables such as “wide”.

  • beq_w(LABEL) long branches if they are equal

Wide branches use 4 bytes to encode instructions (standard transfer instructions are 2 bytes).

7.4. Subroutine (function)

When entering a subroutine, the processor stores the return address in register r14, also known as the link register (lr). By updating the program counter (r15 or pc) from the link register, the instruction is returned after the subroutine call is executed. This process is handled by the following instruction.

  • bl(LABEL)

After LABEL stores the return address in the link register (r14), transfer the execution to the instruction.

  • bx(Rm) transfer to the address specified by Rm.

Usually, send bx(lr) to return from the subroutine. For nested subroutines, before executing the internal subroutine call, the link register of the external range must be saved (usually on the stack).