MC-2 2
MC-2 2
A branch instructions is used to change the flow of execution or to call a routine or sub routine.
Branch instructions allows programs to have subroutine, if-then-else structures and loops.
The change of execution flow forces the program counter PC to point to a new address.
The ARMv5E instruction set includes four different branch instructions: B,BL,BX and BLX
◦ BX{<cond>} Rm
◦ BLX{<cond>} Rm
◦ BLX label
◦ BLX{<cond>} Rm: An unconditional branch with link to the address held in a register. This
instruction copies address of next instruction after BLX into lr and causes branch to the
address held in Rm. It also changes the state to thumb if bit0 of Rm is set.
◦ Note: BX and BLX causes a switch between ARM and Thumb state while branching to a
subroutine.
◦ MOV R0,#5
◦ MOV R1,#0
◦ SUBS R0,#1
If z=0
◦ BNE loop
Backward Jump
◦ MOV R1,#0
◦ SUBS R0,#1
◦ BEQ STOP
◦ B Loop
◦ STOP B STOP
◦ 3. Swap
These instructions are used for moving a single date item in and out of a register.
The datatypes supported are signed and unsigned words(32-bit), half words(16-bit) and
bytes(8 bit).
Syntax:
◦ <LDR|STR>{<cond>}{B} Rd, addressing
Load register R0 with the contents of the memory address pointed to by register R1.
◦ LDR R0, [R1] ; LDR R0,[R1,#0]
This instruction loads a word (32 bit) from the address stored in register R1 and places
it into register R0. Register R1 is called the base address register.
Store the contents of register R0 to the memory address pointed to by register R1.
◦ STR R0, [R1] ; STR R0,[R1,#0]
This instruction stores the contents of register R0 to the address contained in register
R1. The offset from register R1 is Zero. Register R1 is called the base address register.
Preindex
Postindex
Table: Index Methods
Preindex is same as the preindex with writeback but does not update the base register.
Postindex updates the base address register only after the address is used.
NOTE:
The Postindex and Preindex with writeback modes are useful for traversing an array.
Immediate means the address is calculated using the base address register and 12-bit offset
encoded in the instruction.
Register means the address is calculated using the base address register and specific register
contents.
Scaled means the address is calculated using the base address register and a barrel shift
operation.
STRH instruction can be used to store unsigned and signed 16 bit data.
The Multiple register transfer occurs from the memory address held in base address
register Rn.
The Multiple register transfer instructions are more efficient from single register
transfers for
Moving blocks of data around memory
Saving and restoring context
Stacks
The addressing mode supported for load-store multiple instructions are IA,IB,DA,DB.
The Base Register Rn determines the source or destination address for a load-store
multiple instruction.
The Register Rn can be optionally updated after the transfer which occurs where Rn is
followed by the ! Character.
Any subset of the current bank of register can be transferred to memory or fetched
from memory.
With the increment and decrement load multiples, we can access arrays in forward or
backward direction. They also allow for stack push or pull operation.