You copied the Doc URL to your clipboard.

B

Branch.

Syntax

B{cond}{.W} label

where:

cond

is an optional condition code.

.W

is an optional instruction width specifier to force the use of a 32-bit B instruction in Thumb.

label

is a PC-relative expression.

Operation

The B instruction causes a branch to label.

Instruction availability and branch ranges

Table 8 shows the B instructions that are available in ARM and Thumb state. Instructions that are not shown in this table are not available. Notes in brackets show the first architecture version where the instruction is available.

Table 8. Branch instruction availability and range
InstructionARM Thumb, 16-bit encodingThumb, 32-bit encoding
label±32MB(All)±2KB(All T)±16MB[a](All T2)
B{cond} label±32MB(All)-252 to +258(All T)±1MBa(All T2)

[a] Use .W to instruct the assembler to use this 32-bit instruction.


Extending branch ranges

Machine-level B instructions have restricted ranges from the address of the current instruction. However, you can use these instructions even if label is out of range. Often you do not know where the linker places label. When necessary, the linker adds code to enable longer branches. The added code is called a veneer.

in Thumb

You can use the .W width specifier to force B to generate a 32-bit instruction in Thumb code.

B.W always generates a 32-bit instruction, even if the target could be reached using a 16-bit instruction.

For forward references, B without .W always generates a 16-bit instruction in Thumb code, even if that results in failure for a target that could be reached using a 32-bit Thumb instruction.

Condition flags

The B instruction does not change the flags.

Architectures

See Table 8 for details of availability of the B instruction in each architecture.

Example

    B       loopA

See also