ARMInst - UNIT 4
ARMInst - UNIT 4
r0 r0 r0 r0 r0 r0
r1 r1 r1 r1 r1 r1
r2 r2 r2 r2 r2 r2
r3 r3 r3 r3 r3 r3
r4 r4 r4 r4 r4 r4
r5 r5 r5 r5 r5 r5
r6 r6 r6 r6 r6 r6
r7 r7 r7 r7 r7 r7
r8 r8_fiq r8 r8 r8 r8
r9 r9_fiq r9 r9 r9 r9
r10 r10_fiq r10 r10 r10 r10
r11 r11_fiq r11 r11 r11 r11
r12 r12_fiq r12 r12 r12 r12
r13 (sp) r13_fiq r13_svc r13_abt r13_irq r13_undef
r14 (lr) r14_fiq r14_svc r14_abt r14_irq r14_undef
r15 (pc) r15 (pc) r15 (pc) r15 (pc) r15 (pc) r15 (pc)
N Z CV I F T Mode
* Branch
* Branch Exchange (v4T only)
* Coprocessor data transfer
* Coprocessor data operation
* Coprocessor register transfer
*The ARM
Software interrupt
Instruction Set - ARM University Program - V1.0
Conditional Execution
* Most instruction sets only allow branches to be executed conditionally.
* However by reusing the condition evaluation hardware, ARM effectively
increases number of instructions.
• All instructions contain a condition field which determines whether the
CPU will execute them.
• Non-executed instructions soak up 1 cycle.
– Still have to complete cycle so as to allow fetching and decoding of
following instructions.
* This removes the need for many branches, which stall the pipeline (3
cycles to refill).
• Allows very dense in-line code, without branches.
• The Time penalty of not executing several conditional instructions is
frequently less than overhead of the branch
or subroutine call that would otherwise be needed.
31 28 24 20 16 12 8 4 0
Cond
N Z CV I F T Mode
Cond 1 0 1 L Offset
CF Destination 0
Rm 18 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 18 Rs
Rs -1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 -1 Rm
17 cycles 4 cycles
* Note: Compiler does not use early termination criteria to
decide on which order to place operands.
r0 Memory
Source
Register 0x5
for STR
r1 r2
Base Destination
Register 0x200 0x200 0x5 0x5 Register
for LDR
r1
Base
Register 0x200 0x200
r1 Offset r0
Updated Source
Base 0x20c 12 0x5 Register
0x20c
Register for STR
0x200 0x5
r1
Original
Base 0x200
Register
* To auto-increment the base register to location 0x1f4 instead use:
• STR r0, [r1], #-12
* If r2 contains 3, auto-incremenet base register to 0x20c by multiplying
this by 4:
• STR r0, [r1], r2, LSL #2
* When used in a privileged mode, this does the load/store with user mode
privilege.
• Normally used by an exception handler that is emulating a memory
access instruction that would normally execute in user mode.
11 22 33 44
31 24 23 16 15 87 0 31 24 23 16 15 87
0
r1 = 0x100 11 22 33 44 Memory 44 33 22 11 r1 = 0x100
r2 = 0x44 r2 = 0x11
19 18 17 16 16 17 18 19
word16 word16
15 14 13 12 12 13 14 15
half-word14 half-word12 half-word12 half-word14
11 10 9 8 8 9 10 11
word8 word8
7 6 5 4 byte 4 5 6 7
byte
byte6 half-word4 address byte5 half-word6 address
3 2 1 0 0 1 2 3
byte3 byte2 byte1 byte0 byte0 byte1 byte2 byte3
0x418
SP r5 SP
r4 r5
r3 r4
r1 r3
r0 r1
Old SP Old SP r5 Old SP Old SP r0 0x400
r5 r4
r4 r3
r3 r1
r1 r0
SP r0 SP
0x3e8
r12
• This loop transfers 48 bytes in 31 cycles
• Over 50 Mbytes/sec at 33 MHz
1
Rn
temp
2 3
Memory
Rm Rd
Condition Field
Causes an exception trap to the SWI hardware vector
The SWI handler can examine the SWI number to decide what operation has
been requested.
By using the SWI mechanism, an operating system can implement a set of
privileged operations which applications running in user mode can request
(System Calls).
Syntax:
SWI{<cond>} #<SWI number>
Condition Field
N Z C V undefined I F T mode
f s x c
MRS and MSR allow contents of CPSR / SPSR to be transferred to / from a
general purpose register.
Syntax:
MRS{<cond>} Rd,<psr> ; Rd = <psr>
MSR{<cond>} <psr[_fields]>,Rm ; <psr[_fields]> = Rm
where
<psr> = CPSR or SPSR
[_fields] = any combination of ‘fsxc’
Also an immediate form
MSR{<cond>} <psr_fields>,#Immediate
In User Mode, all bits can be read but only the condition flags (_f) can be
written.
Coprocessor instructions:
Coprocessor data operation: CDP
Coprocessor Load/Store: LDC, STC
Coprocessor register transfer: MRC, MCR
(some coprocessors, like P14 and P15, only support MRC and MCR)
A 4-bit coprocessor number (Pxx) has to be specified in these
instructions.
Result in UNDEF exceptions if coprocessor is missing
The most common coprocessors:
P15: System control (cache, MMU, …)
P14: Debug (Debug Communication Channel)
P1, P4, P10: Floating point (FPA, FPE, Maverick, VFP, …)
The assembler can translate the floating-point mnemonics into
coprocessor instructions.
ADD r2,#1
Thumb instruction set limitations:
16-bit Thumb Instruction
Conditional execution only for branches
Source and destination registers identical
Only Low registers (R0-R7) used
Constants are of limited size
31 0 Inline barrel shifter not used
ADDS r2,r2,#1 No MSR, MRS instructions
32-bit ARM Instruction
The ARM Instruction Set - ARM University Program - V1.0