Professional Documents
Culture Documents
Module-5 Theory 3
Module-5 Theory 3
Publication:
Morgan Kaufmann Publishers
Dr. D Khalandar Basha
Branch Instructions
Branch Instructions
Branch Instructions – B
B – Branch.
Syntax: B {<COND>} label
Branches are used to change execution flow.
The address label is stored in the instruction as a signed pc-relative offset and
must be within approximately 32 MB of the branch instruction.
The branch labels are placed at the beginning of the line and are used to mark an
address that can be used later by the assembler to calculate the branch offset.
Don’t write or place any
Example: B label_name image in this area
Branch Instructions – B
The address label is stored in the instruction as a signed pc-relative offset and
must be within approximately 32 MB of the branch instruction.
The branch labels are placed at the beginning of the line and are used to mark an
address that can be used later by the assembler to calculate the branch offset.
Branch Instructions – B
B – Branch.
The example shows a forward and backward branch.
Branch Instructions – BL
Branch Instructions – BL
Example:
Branch Instructions – BX
BX – Branch Exchange.
Syntax: BX {<COND>} Rm
The BX instruction uses an absolute address stored in register Rm.
It is primarily used to branch to and from Thumb code address.
The T bit in the CPSR is updated by the least significant bit of the branch register.
PC <= Rm & 0xfffffffe
T = Rm & 1
Don’t write or place any
The T bit in the cpsr is updated by the least significant bit of the image in this area
branch register..
Dr. D Khalandar Basha
T = Rm & 1
LR = address of the next instruction after the BLX
Dr. D Khalandar Basha
Software Interrupt
Instructions
r0 = 0x12 r0 = 0x12
Dr. D Khalandar Basha
The ARM instruction set provides two instructions to directly control a program
status register (psr).
The MRS instruction transfers the contents of either the cpsr or spsr into a
register; in the reverse direction
The MSR instruction transfers the contents of a register into
the cpsr or spsr.
Together these instructions are used to read and write the cpsr Don’t write or place any
image in this area
and spsr.
Dr. D Khalandar Basha
Loading Constants
Loading Constants
Loading Constants
Example: Loading a 32-bit constant 0xff00ffff into register r0 using LDR instruction.
This example involves a memory access to load the constant, which can be
expensive for time-critical routines.
Loading Constants
Loading Constants
Conditional Execution
Conditional Execution
Conditional Execution
Conditional execution depends upon two components: The condition field is located in the
Condition field instruction, and
the condition flags are located in
Condition flags
the CPSR.
Summary