Professional Documents
Culture Documents
ARM
Advanced RISC Machines
*
*
Every instruction can be conditionally executed.
A load/store architecture
• Data processing instructions act only on registers
– Three operand format
– Combined ALU and shifter for high speed bit manipulation
The ARM Instruction Set • Specific memory access instructions with powerful auto-indexing
addressing modes.
– 32 bit and 8 bit data types
and also 16 bit data types on ARM Architecture v4.
The ARM Instruction Set - ARM University Program - V1.0 1 The ARM Instruction Set - ARM University Program - V1.0 2
The ARM Instruction Set - ARM University Program - V1.0 3 The ARM Instruction Set - ARM University Program - V1.0 4
Register Example:
Register Organisation
User to FIQ Mode
General registers and Program Counter Registers in use Registers in use
User32 / System FIQ32 Supervisor32 Abort32 IRQ32 Undefined32 User Mode FIQ Mode
r0 r0
r0 r0 r0 r0 r0 r0
r1 r1
r1 r1 r1 r1 r1 r1
r2 r2
r2 r2 r2 r2 r2 r2
r3 r3
r3 r3 r3 r3 r3 r3
r4 r4
r4 r4 r4 r4 r4 r4
r5 r5
r5 r5 r5 r5 r5 r5
r6 r6
r6 r6 r6 r6 r6 r6
r7 r7
r7 r7 r7 r7 r7 r7
r8 r8_fiq r8 r8 r8 r8
r8 r8_fiq EXCEPTION r8 r8_fiq
r9 r9_fiq r9 r9_fiq
r9 r9_fiq r9 r9 r9 r9
r10 r10_fiq r10 r10_fiq
r10 r10_fiq r10 r10 r10 r10
r11 r11_fiq r11 r11_fiq
r11 r11_fiq r11 r11 r11 r11
r12 r12_fiq r12 r12_fiq
r12 r12_fiq r12 r12 r12 r12
r13 (sp) r13_fiq r13 (sp) r13_fiq
r13 (sp) r13_fiq r13_svc r13_abt r13_irq r13_undef
r14 (lr) r14_fiq r14 (lr) r14_fiq
r14 (lr) r14_fiq r14_svc r14_abt r14_irq r14_undef
r15 (pc) r15 (pc)
r15 (pc) r15 (pc) r15 (pc) r15 (pc) r15 (pc) r15 (pc)
Return address calculated from User mode
cpsr
PC value and stored in FIQ mode LR cpsr
Program Status Registers spsr_fiq spsr_fiq
cpsr cpsr cpsr cpsr cpsr cpsr
sprsr_fiq
spsr_fiq spsr_svc spsr_abt sprsr_fiq
spsr_irq spsr_undef
sprsr_fiq User mode CPSR copied to FIQ mode SPSR
The ARM Instruction Set - ARM University Program - V1.0 5 The ARM Instruction Set - ARM University Program - V1.0 6
1
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 7 The ARM Instruction Set - ARM University Program - V1.0 8
The ARM Instruction Set - ARM University Program - V1.0 9 The ARM Instruction Set - ARM University Program - V1.0 10
Exception Handling
The Instruction Pipeline
and the Vector Table
* The ARM uses a pipeline in order to increase the speed of the flow of
* When an exception occurs, the core: instructions to the processor.
0x00000000 Reset
• Copies CPSR into SPSR_<mode> • Allows several operations to be undertaken simultaneously, rather than
0x00000004 Undefined Instruction
• Sets appropriate CPSR bits serially.
0x00000008 Software Interrupt
If core implements ARM Architecture 4T and is ARM
0x0000000C Prefetch Abort
currently in Thumb state, then
0x00000010 Data Abort PC FETCH Instruction fetched from memory
ARM state is entered.
0x00000014 Reserved
Mode field bits
0x00000018 IRQ
Interrupt disable flags if appropriate.
PC - 4 DECODE Decoding of registers used in instruction
• Maps in appropriate banked registers 0x0000001C FIQ
The ARM Instruction Set - ARM University Program - V1.0 11 The ARM Instruction Set - ARM University Program - V1.0 12
2
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 13 The ARM Instruction Set - ARM University Program - V1.0 14
The ARM Instruction Set - ARM University Program - V1.0 17 The ARM Instruction Set - ARM University Program - V1.0 18
3
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 19 The ARM Instruction Set - ARM University Program - V1.0 20
The ARM Instruction Set - ARM University Program - V1.0 21 The ARM Instruction Set - ARM University Program - V1.0 22
The ARM Instruction Set - ARM University Program - V1.0 23 The ARM Instruction Set - ARM University Program - V1.0 24
4
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 25 The ARM Instruction Set - ARM University Program - V1.0 26
The ARM Instruction Set - ARM University Program - V1.0 29 The ARM Instruction Set - ARM University Program - V1.0 30
5
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 33 The ARM Instruction Set - ARM University Program - V1.0 34
The ARM Instruction Set - ARM University Program - V1.0 35 The ARM Instruction Set - ARM University Program - V1.0 36
6
Handout
The ARM Instruction Set
Multiply-Long and
Load / Store Instructions
Multiply-Accumulate Long
* Instructions are * The ARM is a Load / Store Architecture:
• MULL which gives RdHi,RdLo:=Rm*Rs • Does not support memory to memory data processing operations.
• MLAL which gives RdHi,RdLo:=(Rm*Rs)+RdHi,RdLo • Must move data values into registers before using them.
* However the full 64 bit of the result now matter (lower precision * This might sound inefficient, but in practice isn’t:
multiply instructions simply throws top 32bits away) • Load data values from memory into registers.
• Need to specify whether operands are signed or unsigned • Process data in registers using a number of data processing
* Therefore syntax of new instructions are: instructions which are not slowed down by memory access.
• UMULL{<cond>}{S} RdLo,RdHi,Rm,Rs • Store results from registers out to memory.
• UMLAL{<cond>}{S} RdLo,RdHi,Rm,Rs * The ARM has three sets of instructions which interact with main
• SMULL{<cond>}{S} RdLo, RdHi, Rm, Rs memory. These are:
• SMLAL{<cond>}{S} RdLo, RdHi, Rm, Rs • Single register data transfer (LDR / STR).
* Not generated by the compiler. • Block data transfer (LDM/STM).
• Single Data Swap (SWP).
Warning : Unpredictable on non-M ARMs.
The ARM Instruction Set - ARM University Program - V1.0 37 The ARM Instruction Set - ARM University Program - V1.0 38
Load and Store Word or Byte: Load and Store Word or Byte:
Offsets from the Base Register Pre-indexed Addressing
r0
* As well as accessing the actual location contained in the base register, * Example: STR r0, [r1,#12] Memory Source
these instructions can access a location offset from the base register 0x5 Register
for STR
pointer.
Offset
* This offset can be
12 0x20c 0x5
• An unsigned 12bit immediate value (ie 0 - 4095 bytes).
r1
• A register, optionally shifted by an immediate value Base
Register 0x200 0x200
* This can be either added or subtracted from the base register:
• Prefix the offset value or register with ‘+’ (default) or ‘-’.
* This offset can be applied:
• before the transfer is made: Pre-
Pre-indexed addressing
* To store to location 0x1f4 instead use: STR r0, [r1,#-12]
– optionally auto-
auto-incrementing the base register, by postfixing the
instruction with an ‘!’. * To auto-increment base pointer to 0x20c use: STR r0, [r1, #12]!
• after the transfer is made: Post-
Post-indexed addressing * If r2 contains 3, access 0x20c by multiplying this by 4:
– causing the base register to be auto-
auto-incremented.
incremented • STR r0, [r1, r2, LSL #2]
The ARM Instruction Set - ARM University Program - V1.0 41 The ARM Instruction Set - ARM University Program - V1.0 42
7
Handout
The ARM Instruction Set
0x5
* When used in a privileged mode, this does the load/store with user mode
0x200
r1 privilege.
Original
Base 0x200 • Normally used by an exception handler that is emulating a memory
Register access instruction that would normally execute in user mode.
* 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
The ARM Instruction Set - ARM University Program - V1.0 43 The ARM Instruction Set - ARM University Program - V1.0 44
The ARM Instruction Set - ARM University Program - V1.0 45 The ARM Instruction Set - ARM University Program - V1.0 46
00 00 00 44 00 00 00 11
r2 = 0x44 r2 = 0x11
The ARM Instruction Set - ARM University Program - V1.0 47 The ARM Instruction Set - ARM University Program - V1.0 48
8
Handout
The ARM Instruction Set
The ARM Instruction Set - ARM University Program - V1.0 49 The ARM Instruction Set - ARM University Program - V1.0 50
The ARM Instruction Set - ARM University Program - V1.0 53 The ARM Instruction Set - ARM University Program - V1.0 54
9
Handout
The ARM Instruction Set
Direct functionality of
Example: Block Copy
Block Data Transfer
* When LDM / STM are not being used to implement stacks, it is clearer to • Copy a block of memory, which is an exact multiple of 12 words long
specify exactly what functionality of the instruction is: from the location pointed to by r12 to the location pointed to by r13. r14
• i.e. specify whether to increment / decrement the base pointer, before or points to the end of block to be copied.
after the memory access.
* In order to do this, LDM / STM support a further syntax in addition to ; r12 points to the start of the source data
the stack one: ; r14 points to the end of the source data
• STMIA / LDMIA : Increment After ; r13 points to the start of the destination data
r13
loop LDMIA r12!, {r0-r11} ; load 48 bytes
• STMIB / LDMIB : Increment Before
STMIA r13!, {r0-r11} ; and store them r14 Increasing
• STMDA / LDMDA : Decrement After Memory
CMP r12, r14 ; check for the end
• STMDB / LDMDB : Decrement Before BNE loop ; and loop until done
r12
• This loop transfers 48 bytes in 31 cycles
• Over 50 Mbytes/sec at 33 MHz
The ARM Instruction Set - ARM University Program - V1.0 55 The ARM Instruction Set - ARM University Program - V1.0 56
* Atomic operation of a memory read followed by a memory write Cond 1 1 1 1 Comment field (ignored by Processor)
which moves byte or word quantities between registers and
memory.
* Syntax: Condition Field
• SWP{<cond>}{B} Rd, Rm, [Rn]
* In effect, a SWI is a user-defined instruction.
1
* It causes an exception trap to the SWI hardware vector (thus causing a
Rn
temp
change to supervisor mode, plus the associated state saving), thus causing
the SWI exception handler to be called.
2 3 * The handler can then examine the comment field of the instruction to
Memory decide what operation has been requested.
Rm Rd
* By making use of the SWI mechansim, an operating system can
* Thus to implement an actual swap of contents make Rd = Rm. implement a set of privileged operations which applications running in
user mode can request.
* The compiler cannot produce this instruction.
* See Exception Handling Module for further details.
The ARM Instruction Set - ARM University Program - V1.0 57 The ARM Instruction Set - ARM University Program - V1.0 58
10