Instruction Set-II (1)
Instruction Set-II (1)
Instruction Set-II (1)
1
CONTENTS
• Branch Instructions
• Load Store Instructions
2
BRANCH INSTRUCTIONS
3
The ARM instruction set includes four different
branch instructions.
SYNTAX: B{<cond>} label
BL{<cond>} label
BX{<cond>} Rm
BLX{<cond>} label | Rm
4
T refers to the Thumb bit in the cpsr.
When instructions set T, the ARM switches to
Thumb state.
5
An Illustration Of Branch Instruction
This example shows a forward and backward branch. The
forward branch skips three instructions. The backward
branch creates an infinite loop.
B forward
ADD r1, r2, #4
ADD r0, r6, #2
ADD r3, r7, #4
forward
SUB r1, r2, #4
backward
ADD r1, r2, #4
SUB r1, r2, #4
ADD r4, r6, r7
B backward 6
• Most assemblers hide the details of a branch
instruction encoding by using labels.
• Here forward and backward are the labels.
• 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.
7
CONTD….BL Branch Instruction
The branch with link, or BL, instruction is similar to the B
instruction but overwrites the link register lr with a return
address. It performs a subroutine call.
To return from a subroutine, you copy the link register to
the pc.
BL subroutine ; branch to subroutine
CMP r1, #5 ; compare r1 with 5
MOV EQ r1, #0 ; if (r1==5) then
r1 = 0
:
subroutine
<subroutine code>
MOV pc, lr ; return by moving pc =
lr 8
CONTD….
9
LOAD STORE INSTRUCTIONS
10
STACK OPERATIONS
11
CONTD….
13
14
The STMFD instruction pushes registers onto the
stack, updating the sp. A push onto a full
descending stack. You can see that when the stack
grows the stack pointer points to the last full entry
in the stack.
PRE r1 = 0x00000002
r4 = 0x00000003
sp = 0x00080014
STMFD sp!, {r1,r4}
15
16
ARM has specified an ARM-Thumb Procedure
Call Standard (ATPCS) that defines how routines
are called and how registers are allocated. In the
ATPCS, stacks are defined as being full descending
stacks.
Thus, the LDMFD and STMFD instructions
provide the pop and push functions, respectively
17
SWAP INSTRUCTIONS
19
An Illustration Of Swap Instruction
PRE
mem32[0x9000] = 0x12345678
r0 = 0x000000
r1 = 0x11112222
r2 = 0x00009000
SWP r0, r1, [r2]
POST
mem32[0x9000] = 0x11112222
r0 = 0x12345678
r1 = 0x11112222
r2 = 0x00009000
20
CONTD…
21
Program Status Register Instructions
• 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 and vice versa.
• MSR instruction
- Transfer the contents of general-purpose register to PSR.
• Together these instructions are used to read and write the cpsr and
spsr.
• Fields can be any combination of control(c), extension (x), status (s),
and flags (f ). These fields relate to particular byte regions in a psr.
33
• Syntax: MRS{<cond>} Rd,<cpsr|spsr>
• MSR{<cond>} <cpsr|spsr>_<fields>,Rm
• MSR{<cond>} <cpsr|
spsr>_<fields>,#immediate
PSR byte fields
34