ARM Instruction Set PDF
ARM Instruction Set PDF
ARM Instruction Set PDF
by
arn, KITCOEK
Instruction Set Summary
The Condition Field
0x8008 XX Fetch
Ex: ADD R1, R2, R3, LSL #3 Ex: ADD R1, R2, R3, LSL R4
Shifts: 2nd operand is 8bit #no.
•When the shift amount is specified in the instruction, it is contained in a 5 bit field which
may take any value from 0 to 31.
•A logical shift left (LSL) takes the contents of Rm and moves each bit by the specified
amount to a more significant position.
•The least significant bits of the result are filled with zeros, and the high bits of Rm which
do not map into the result are discarded, except that the lest discarded bit
becomes the shifter carry output which may be latched into the C bit of the CPSR when
the ALU operation is in the logical class (see above). (For arithmetic operations C will get
update as per arithmetic result)
For example, the effect of LSL #5 is shown in Figure above Logical shift left.
Logical shift right
Arithmetic shift right
• PLACE
Most often used LDR/STR inst.
Loads Stores Size and type
LDR STR Word 32 bit
LDRB STRB Byte 8 bits
LDRH STRH Half word 16 bits
LDRSB -- Signed byte sign extended
32 bits
LDRSH -- Signed Half word sign
extended 32 bit
LDM STM Multiple words
Examples: cont’d
LDRH r11, [r0]; load half word in to r11 pointed
;by r0 = [0x00008000]
First store
then
increment
consider the transfer of R1, R5 and R7 in the case where
Rn=0x1000 and write back of the modified base is required (W=1)
Pre-increment addressing: Full stack Ascending
STRMFA R0!, {R1, R5, R7}
First increment then store
Base
register
pointing
to filled
memory
Stack
like
8051
consider the transfer of R1, R5 and R7 in the case where
Rn=0x1000 and write back of the modified base is required (W=1)
Post-decrement addressing: Empty stack Descending
STMED R0!, {R1, R5, R7}
Lower First
register store,
at lower then
address incr
consider the transfer of R1, R5 and R7 in the case where
Rn=0x1000 and write back of the modified base is required (W=1)
Pre-decrement addressing: Full stack Descending
STMFD R0!, {R1, R5, R7}
Stack
First
like
decr
8085
then
stor
Use of the S bit
• When the S bit is set in a LDM/STM instruction
its meaning depends on whether or not
– R15 is in the transfer list
– and on the type of instruction (LDM/STM).
• The S bit should only be set if the instruction is
to execute in a privileged mode.
What is difference between
mov pc lr and movs pc lr ?
STM with R15 in transfer list and S bit
set (Save User mode registers)
• The registers transferred are taken from the
User bank rather than the bank corresponding
to the current mode.
• This can be useful when you have switched to
Supervisory mode from user mode (due to
execution of SWI instruction ) and now you
want to save contest of User mode
• This instruction is executed from privileged
mode
LDM with R15 in transfer list and S bit set
Mode change: privileged to User
• If the instruction is a LDM then SPSR_<mode> is
transferred to CPSR at the same time as R15 is loaded.
Example : you are switching from Supervisory mode to
USER mode the contest of User mode (set of stored
registers and CPSR) will be loaded in required registers
• PC will be loaded with, where you want to jump
• Saved PSR_mode will be restored back in CPSR
– so you got all flags when you moved to user mode from
supervisory mode
• This instruction will be executed from privileged mode
– This is a clear case of contest switching from privileged
mode to User mode
R15 not in list and S bit set (User bank
transfer)
• For both LDM and STM instructions, the User
bank registers are transferred rather than the
register bank corresponding to the current
mode.
• This is useful for saving the user state on
process switches.
• Base write-back shall not be used when this
mechanism is employed.
Use of R15 as the base register
• R15 must not be used as the base register in
any LDM or STM instruction
Assembler syntax
• <LDM|STM>{cond}<FD|ED|FA|EA|IA|IB|DA|DB>
Rn{!},<Rlist>{^}
• where:
– {cond} is a two-character condition mnemonic,
– Rn is an expression evaluating to a valid register number
– <Rlist> is a list of registers and register ranges enclosed in
{} (e.g. {R0,R2- R7,R10}).
– {!} (if present) requests write-back (W=1), otherwise W=0
– {^} (if present) set S bit to load the CPSR along with the PC,
or force transfer of user bank when in privileged mode
Addressing mode names
• There are different assembler mnemonics for
each of the addressing modes, depending on
whether the instruction is being used to
support stacks or for other purposes.
Addressing mode names
• FD, ED, FA, EA define pre/post indexing and the
up/down bit by reference to the form of stack
required.
– F: Full stack (a pre-index has to be done before storing
to the stack)
– E: Empty stack: Post- inc/decrement addressing
– A: The stack is ascending (an STM will go up and LDM
down)
– D: The stack is descending (an STM will go down and
LDM up)
Addressing mode names
• The following symbols allow
control when LDM/STM are
not being used for stacks:
– IA Increment After
– IB Increment Before(8051)
– DA Decrement After
– DB Decrement Before(8085)
9000
9004 00000009
9008 00000008
900c 0000007
Examples
• LDMFD SP!,{R0,R1,R2} ;unstack 3 registers (8085)
• LDMFD SP!,{R15} ;R15 <- [SP],CPSR unchanged
• STMFD R13 ,{R0-R14}^ ; R13(SP)
;save user mode regs on stack
;(allowed only in privileged modes)
• LDMFD SP!,{R15}^ ;R15 <- [SP], ^ indicate set S bit
;CPSR <- SPSR_mode (allowed only in
;privileged modes)
Nested CALL
Function 1
Main Program Function 2
.
STMFD SP! (regs, LR) .
. .
.
. .
BL fun1 . .
.
BL fun2
ADD R1 … .
.
. MOV PC, LR
.
.
.
LDMFD SP! (regs, LR)
MOV PC, LR
Examples
• These instructions may be used to save state on
subroutine entry, and restore it efficiently on
return to the calling routine:
• STMED SP!,{R0-R3,R14};
;save R0 to R3 to use as workspace
and R14(Lr) for returning
• BL somewhere
;this nested call will overwrite R14
• LDMED SP!,{R0-R3,R15}
;restore workspace and return
Single Data Swap: SWP
• The data swap instruction is used to swap a
byte or word quantity between a register and
external memory.
• This instruction is implemented as a memory
read followed by a memory write which are
“locked” together (the processor cannot be
interrupted until both operations have
completed, and the memory manager is
warned to treat them as inseparable).
Encoding
Syntax:
• UMULL{<cond>}{S} <Rd_LSW>, <Rd_MSW>, <Rm>,
<Rs>
• RTL:
if(cond)
Rd_MSW:Rd_LSW <- Rs • Rm
• Flags updated if S used:N, Z (V, C are unpredictable)
UMULL: Usage and Examples:
UMULL performs an unsigned 32x32 multiply
operation. The product of Rm and Rs is
stored as a 64-bit unsigned value in the
register pair Rd_MSW:Rd_LSW.
• All values are interpreted as unsigned binary.
• The instruction below stores the product of R2
and R3 as a 64-bit number in R1:0.
– UMULL R0, R1, R2, R3
UMLAL – Unsigned Multiply-
Accumulate Long
• Syntax:
UMLAL{<cond>}{S} <Rd_LSW>, <Rd_MSW>, <Rm>,
<Rs>
• RTL:
if(cond)
• Rd_MSW:Rd_LSW <= Rd_MSW:Rd_LSW + (Rs • Rm)
• Flags updated if S used:N, Z (V, C are unpredictable)
Usage and Examples: UMLAL
• RSB r0, r2, r2, LSL #3; r0= r2*8 -r2 = r2*7
SWI has type of S/W interrupt in bits 8-23 and data (if any) in bits ;0-7.
Assumes R13_svc points to a suitable stack
• STMFD R13!,{R0-R2,R14}; save work registers and return address
• LDR R0,[R14,#-4] ;get SWI instruction
• BIC R0,R0,#0xFF000000; clear top 8 bits
• MOV R1,R0,LSR#8 ;get routine offset
• ADR R2,EntryTable ;get start address of entry table
• LDR R15,[R2,R1,LSL#2] ;branch to appropriate routine
• WriteIRtn ;enter with character in R0 bits 0-7
• ......
• LDMFD R13!,{R0-R2,R15}^ ;restore workspace and return restoring
processor mode and flags