Arm7tdmi Instruction Set Reference
Arm7tdmi Instruction Set Reference
University of Wisconsin-Madison
ECE 353/315
ARM7TDMI
Instruction Set
Reference
Michael G. Morrow
2009
Last updated 10/8/2009 4:43 PM
Table of Contents
1 Instruction Encoding ............................................................................................................................................1
1.1 ARM7TDMI – ARM Instructions .............................................................................................................................. 1
1.2 ARM7TDMI – THUMB Instructions .......................................................................................................................... 2
2 Conditional Execution...........................................................................................................................................2
2.1 Condition Field ...................................................................................................................................................... 2
2.2 Condition Codes .................................................................................................................................................... 2
3 Addressing, Operands and Directives ...................................................................................................................3
3.1 General Notes ....................................................................................................................................................... 3
3.2 Shifter Operands ................................................................................................................................................... 3
3.3 Load/Store Register Addressing Modes ................................................................................................................... 6
3.4 Miscellaneous Load/Store Addressing Modes ........................................................................................................... 8
3.5 Memory Allocation and Operand Alignment............................................................................................................. 9
3.6 Miscellaneous Assembler Directives ....................................................................................................................... 10
4 Instruction Descriptions .....................................................................................................................................12
4.1 General Information ............................................................................................................................................. 12
4.2 ADC – Add with Carry........................................................................................................................................... 12
4.3 ADD - Add ........................................................................................................................................................... 13
4.4 AND – Bit-wise AND ............................................................................................................................................. 13
4.5 B, BL – Branch, Branch and Link ........................................................................................................................... 14
4.6 BIC – Bit Clear ..................................................................................................................................................... 15
4.7 BX – Branch and Exchange ................................................................................................................................... 15
4.8 CMN – Compare Negative ..................................................................................................................................... 16
4.9 CMP - Compare .................................................................................................................................................... 16
4.10 EOR – Bit-wise Exclusive-OR ................................................................................................................................. 17
4.11 LDM – Load Multiple............................................................................................................................................. 17
4.12 LDR – Load Register............................................................................................................................................. 19
4.13 LDRB – Load Register Byte ................................................................................................................................... 20
4.14 LDRH – Load Register Halfword ............................................................................................................................ 20
4.15 LDRSB – Load Register Signed Byte ...................................................................................................................... 21
4.16 LDRSH – Load Register Signed Halfword ............................................................................................................... 21
4.17 MLA – Multiply-Accumulate ................................................................................................................................... 22
4.18 MOV – Move ........................................................................................................................................................ 22
4.19 MRS – Move PSR into General-Purpose Register.....................................................................................................23
4.20 MSR – Move to Status Register from ARM Register ................................................................................................ 23
4.21 MUL – Multiply ..................................................................................................................................................... 24
4.22 MVN – Move Negative .......................................................................................................................................... 25
4.23 ORR – Bit-wise Inclusive-OR ................................................................................................................................. 25
4.24 RSB – Reverse Subtract ........................................................................................................................................ 26
4.25 RSC – Reverse Subtract with Carry........................................................................................................................26
4.26 SBC – Subtract with Carry .................................................................................................................................... 27
4.27 SMLAL – Signed Multiply-Accumulate Long ............................................................................................................ 27
4.28 SMULL – Signed Multiply Long .............................................................................................................................. 28
4.29 STM – Store Multiple ............................................................................................................................................ 28
4.30 STR – Store Register ............................................................................................................................................ 30
4.31 STRB – Store Register Byte .................................................................................................................................. 30
4.32 STRH – Store Register Halfword............................................................................................................................31
4.33 SUB - Subtract ..................................................................................................................................................... 31
4.34 SWI – Software Interrupt ..................................................................................................................................... 32
4.35 SWP - Swap......................................................................................................................................................... 32
4.36 SWPB – Swap Byte .............................................................................................................................................. 33
4.37 TEQ – Test Equivalence ........................................................................................................................................ 34
4.38 TST - Test ........................................................................................................................................................... 34
4.39 UMLAL – Unsigned Multiply-Accumulate Long ........................................................................................................ 35
4.40 UMULL – Unsigned Multiply Long .......................................................................................................................... 35
5 Pseudo-Instructions ...........................................................................................................................................36
5.1 ADR – Load Address (short-range) ........................................................................................................................ 36
5.2 ADRL – Load Address (medium-range) .................................................................................................................. 36
5.3 ASR – Arithmetic Shift Right ................................................................................................................................. 36
5.4 LDR – Load Register............................................................................................................................................. 37
5.5 LSL – Logical Shift Left ......................................................................................................................................... 37
5.6 LSR – Logical Shift Right....................................................................................................................................... 37
5.7 NOP – No Operation ............................................................................................................................................. 38
5.8 POP - Pop ............................................................................................................................................................ 38
5.9 PUSH - Push ........................................................................................................................................................ 38
5.10 ROR – Rotate Right .............................................................................................................................................. 38
5.11 RRX – Rotate Right with Extend ............................................................................................................................ 39
i
ii
1 Instruction Encoding
1.1 ARM7TDMI – ARM Instructions
The ARM7TDMI uses a fixed-length, 32-bit instruction encoding scheme for all ARM instructions. The basic encoding for all
ARM7TDMI instructions is shown below. Individual instruction descriptions and encodings are shown in section 4 of this document.
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
Page 1
1.2 ARM7TDMI – THUMB Instructions
The ARM7TDMI uses a fixed-length, 16-bit instruction encoding scheme for all Thumb
instructions. The Thumb instruction set is a subset of the ARM instruction set, and is intended to
permit a higher code density (smaller memory requirement) than the ARM instruction set in
many applications. The processor executes in Thumb mode when bit 5 of the CPSR is 1.
Exception processing is always done in ARM mode; the processor automatically switches to
ARM mode when entering an exception mode. Use of the Thumb instruction set will not be
required in ECE 353/315, and so is not covered here.
2 Conditional Execution
2.1 Condition Field
All ARM7TDMI instructions can be executed conditionally, based on a 4-bit condition field in
the instruction. The processor tests the state of the condition flags in the CPSR (N, Z, V, C), and
if the condition flag state matches the condition, the instruction executes normally. If the
condition flag state does not match the condition, the instruction is executed as a NOP (no
operation).
Opcode Mnemonic
[31:28] Extension Meaning Condition flag state
0000 EQ Equal Z==1
0001 NE Not equal Z==0
0010 CS/HS Carry set / unsigned higher or same C==1
0011 CC/LO Carry clear / unsigned lower C==0
0100 MI Minus / negative N==1
0101 PL Plus / positive or zero N==0
0110 VS Overflow V==1
0111 VC No overflow V==0
1000 HI Unsigned higher (C==1) AND (Z==0)
1001 LS Unsigned lower or same (C==0) OR (Z==1)
1010 GE Signed greater than or equal N == V
1011 LT Signed less than N != V
1100 GT Signed greater than (Z==0) AND (N==V)
1101 LE Signed less than or equal (Z==1) OR (N!=V)
1110 AL Always (unconditional) Not applicable
1111 (NV) Never Obsolete, unpredictable in ARM7TDMI
Page 2
3 Addressing, Operands and Directives
3.1 General Notes
In general, using R15 (PC) as the destination register is not appropriate for most
instructions. Many instructions will have unpredictable behavior if R15 is the destination.
The ARM supports instruction set extensions by reserving certain bit combinations in
the operand fields of otherwise valid instructions. The assembler will ensure that these
bit combinations are not used, but these must be avoided when hand-coding
instructions.
The notation SBZ means “should be zeros”, SBO means “should be ones”.
Syntax: #<immediate>
Example: CMP R0, #7
Encoding:
11 10 9 8 7 6 5 4 3 2 1 0
rotate_imm immediate_8
Page 3
3.2.2 Register Operands
The register value is used directly. The C flag is unchanged. Note that this is actually a
form of the Register Operand, Logical Shift Left by Immediate option (see below) with a
0-bit shift.
Syntax: <Rm>
Example: CMP R0, R1
Encoding:
11 10 9 8 7 6 5 4 3 2 1 0
0 0 0 0 0 0 0 0 Rm
Page 4
3.2.6 Register Operand, Logical Shift Right by Register
The register value is shifted right by a value contained in a register. The C flag will be
updated with the last value shifted out of Rm unless the value in Rs is 0.
Page 5
3.2.10 Register Operand, Rotate Right by Register
The register value is rotated right by a value contained in a register. The C flag will be
updated with the last value shifted out of Rm unless the value in Rs is 0.
Note that the ARM processor does not support a direct addressing mode for load/store
operation. (Direct addressing is where the address is encoded in the instruction.)
However, a label (i.e. a memory location name) can be specified as the memory
address in a load/store instruction. In this case, the assembler will attempt to reach the
label using the “base register with immediate offset” mode, using the PC as the base
register and computing the required offset.
Page 6
3.3.3 Base register with shifted register offset
[Rn, +/-<Rm>, <shift> #<shift_immediate>]
memory_address = Rn +/- shifted_Rm (see below)
Rn is unchanged after instruction
The shifted register offset modes are specified in the same manner as other shifter
operands, where the <shift> #<shift_immediate> fields can be one of the below.
Logical shift left - LSL #0-31
Logical shift right - LSR #1-32
Arithmetic shift right - ASR #1-32
Rotate right - ROR #1-32
Rotate right with extend - RRX
Page 7
3.4 Miscellaneous Load/Store Addressing Modes
These options apply only to the LDRSB, LDRH, LDRSH, STRH instructions. There are six
options that can be specified for the addressing mode, as listed below. All options
include a base register. See the ARM Architecture Reference manual section 5.3 for
more detailed information.
Note that the ARM processor does not support a direct addressing mode for load/store
operation. (Direct addressing is where the address is encoded in the instruction.)
However, a label (i.e. a memory location name) can be specified as the memory
address. In this case, the assembler will attempt to reach the label using the base
register with immediate offset mode, using the PC as the base register and computing
the required offset.
Page 8
3.5 Memory Allocation and Operand Alignment
This section presents an abridged list of the most commonly used assembler directives.
Full documentation is available in the ARM Assembler manuals.
3.5.1 Literals
Literal substitutions are indicated with the EQU directives.
Syntax: name EQU expr {,type}
Description: The EQU directive informs the assembler to perform a literal substitution
whenever it encounters name in the source file, replacing it with expr. The expression
can be a numeric constant, a relative address, or an absolute address. If an absolute
address is specified, then the type field can be one of ARM, THUMB, CODE16, CODE32,
or DATA. (Note that only ARM or DATA are applicable to code written in ECE 353/315.)
Page 9
numeric constants or program-relative expressions (i.e. labels). DCDU allocates without
ensuring alignment. If DCDU is followed by a label that is a branch target, use the
ALIGN directive to ensure that the label is properly aligned.
Page 10
3.6.4 ENTRY – Code Entry Point
Syntax: ENTRY
Description: The ENTRY directive indicates the point in the code where program
execution should begin. There should be only ONE entry point per complete program.
Note that in developing the software for an embedded system, execution will begin at
the reset vector, so the code entry point will be determined by what code is linked at
that address and the ENTRY directive is not used.
Page 11
4 Instruction Descriptions
4.1 General Information
A number of ARM7TDMI instructions will not be used in conjunction with the ADuC7026
processor used in ECE 353 and ECE 315. These instructions are listed below, and do not
have detailed information in this section. Further information on these instructions can
be obtained from the ARM Architecture Reference Manual.
CDP – Coprocessor Data Processing
LDC – Load Coprocessor
LDRBT – Load Register Byte with Translation
LDRT – Load Register with Translation
MCR - Move to Coprocessor from ARM Register
MRC - Move to ARM Register from Coprocessor
STC - Store Coprocessor
STRBT - Store Register Byte with Translation
STRT - Store Register with Translation
RTL:
if(cond)
Rd Rn + shifter_operand + C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 1 0 1 S Rn Rd shifter operand
Page 12
4.3 ADD - Add
Syntax:
ADD{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
RTL:
if(cond)
Rd Rn + shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 1 0 0 S Rn Rd shifter operand
RTL:
if(cond)
Rd Rn AND shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 0 0 0 S Rn Rd shifter operand
Page 13
4.5 B, BL – Branch, Branch and Link
Syntax:
B{<cond>} <target_address>, BL{<cond>} <target_address>
RTL:
if(cond)
if(L==1)
R14 address of next instruction
PC PC + (signed_immediate_24 << 2)
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 0 1 L signed_immediate_24
To return from a subroutine after using BL to call it, the preferred method is to use BX
LR. If the subroutine used the STM instruction to store a group of registers and the
return address on the stack (i.e. STMFD R13!, {R0-R5, LR} ), then the return should be
executed in the complementary fashion by placing the saved link register value into the
PC (i.e. LDMFD R13!, {R0-R5, PC} ).
Page 14
4.6 BIC – Bit Clear
Syntax:
BIC{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
RTL:
if(cond)
Rd Rn AND NOT shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 1 1 0 S Rn Rd shifter operand
RTL:
if(cond)
T flag Rm[0]
PC Rm & 0xFFFFFFFE
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 1 0 0 1 0 SB0 SB0 SB0 0 0 0 1 Rm
Page 15
4.8 CMN – Compare Negative
Syntax:
CMN{<cond>} <Rn>, <shifter_operand>
RTL:
if(cond)
Rn + shifter_operand
Flags updated:
N, Z, V, C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 0 1 0 1 Rn Rd shifter operand
RTL:
if(cond)
Rn - shifter_operand
Flags updated:
N, Z, V, C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 0 1 0 1 Rn Rd shifter operand
Page 16
4.10 EOR – Bit-wise Exclusive-OR
Syntax:
EOR{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
RTL:
if(cond)
Rd Rn XOR shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 0 0 1 S Rn Rd shifter operand
RTL:
if(cond)
start_address Rn
for i = 0 to 14
if(register_list[i] == 1)
Ri memory[next_address]
if(register_list[15] == 1)
PC memory[next_address] & 0xFFFFFFFC
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 0 0 P U 0 W 1 Rn register_list
Page 17
Usage and Examples:
The LDM instruction permits block moves of memory to the registers and enables
efficient stack operations. The registers may be listed in any order, but the registers are
always loaded in order with the lowest numbered register getting the value form the
lowest memory address. If Rn is also listed in the register list and register writeback (W
bit) is set, the final value in Rn is unpredictable.
The addressing_mode field determines how next_address is calculated (bits P & W),
which control how the address is updated in conjunction with each register load. The
four addressing_mode values are;
IA - increment address by 4 after each load (post-increment)
IB - increment address by 4 before each load (pre-increment)
DA - decrement address by 4 after each load (post-decrement)
DB - decrement address by 4 before each load (pre-decrement)
The “!” following Rn controls the value of the writeback bit (bit W), and signifies that Rn
should be updated with the ending address at the end of the instruction. If the “!” is
not present (W=0), the value of Rn will be unchanged at the end of the instruction.
For use in conjunction with stack addressing, four alternative names can be used for
the addressing modes. These names are based on the type of stack being used instead
of the addressing mode being used. This eliminates confusion in coding stack push and
pop operations, since the type of stack will be the same for both the LDM and STM
instructions. In ARM syntax, a full stack is one where the stack pointer points to the last
used (full) location. An empty stack is one where the stack pointer points to the next
available (empty) stack location. As well, a stack can grow through increasing memory
addresses (ascending), or downward through decreasing memory addresses
(descending). The table below summarizes the stack addressing modes.
Page 18
The instructions below demonstrate a push operation followed by a pop operation
assuming an empty-ascending stack. Note that by including the link register (R14) in
the push operation, and the PC in the pop operation, a subroutine will return to the
caller as part of the context save/restore.
STMEA R13!, {R0, R2-R3, LR} ;memory[R13] R0
;memory[R13+4] R2
;memory[R13+8] R3
;memory[R13+12] R14
;R13 R13 + 16
RTL:
if(cond)
Rd memory[memory_address]
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 1 I P U 0 W 1 Rn Rd addressing_mode
If the memory address is not word-aligned, the value read is rotated right by 8 times
the value of bits [1:0] of the memory address. If R15 is specified as the destination, the
value is loaded from memory and written to the PC, effecting a branch.
Page 19
4.13 LDRB – Load Register Byte
Syntax:
LDRB{<cond>} <Rd>, <addressing_mode>
RTL:
if(cond)
Rd[7:0] memory[memory_address], Rd[31:8] 0
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 1 I P U 1 W 1 Rn Rd addressing_mode
RTL:
if(cond)
Rd[15:0] memory[memory_address], Rd[31:16] 0
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 P U I W 1 Rn Rd addr_mode 1 0 1 1 addr_mode
Page 20
4.15 LDRSB – Load Register Signed Byte
Syntax:
LDRSB{<cond>} <Rd>, <addressing_mode>
RTL:
if(cond)
Rd[7:0] memory[memory_address]
Rd[31:8] Rd[7] (sign-extension)
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 P U I W 1 Rn Rd addr_mode 1 1 0 1 addr_mode
RTL:
if(cond)
Rd[15:0] memory[memory_address], Rd[31:16] Rd[15] (sign-extension)
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 P U I W 1 Rn Rd addr_mode 1 1 1 1 addr_mode
Page 21
4.17 MLA – Multiply-Accumulate
Syntax:
MLA{<cond>}{S} <Rd >, <Rm>, <Rs>, <Rn>
RTL:
if(cond)
Rd Rn + (Rs • Rm)
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 0 0 1 S Rd Rn Rs 1 0 0 1 Rm
RTL:
if(cond)
Rd shifter_operand
if(S==1 and Rd==R15)
CPSR SPSR
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 1 0 1 S SBZ Rd shifter operand
Page 22
4.19 MRS – Move PSR into General-Purpose Register
Syntax:
MRS{<cond>} <Rd >, CPSR
MRS{<cond>} <Rd >, SPSR
RTL:
if(cond)
Rd CPSR/SPSR
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 1 0 R 0 0 SB0 Rd SB0
RTL:
if(cond)
CPSR/SPSR immediate/register value
Flags updated:
N/A
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 1 1 0 R 1 0 field_mask SB0 rotate_imm immediate
cond 0 0 0 1 0 R 1 0 field_mask SB0 SBZ 0 0 0 0 Rm
Page 23
The <fields> indicate which fields of the CPSR/SPSR be written to should be allowed to
be changed. This limits any changes just to the fields intended by the programmer. The
allowed fields are;
c sets the control field mask bit (bit 16)
x sets the extension field mask bit (bit 17)
s sets the status field mask bit (bit 18)
f sets the flags field mask bit (bit 19)
One or more fields may be specified.
RTL:
if(cond)
Rd Rs • Rm
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 0 0 0 S Rd SBZ Rs 1 0 0 1 Rm
Page 24
4.22 MVN – Move Negative
Syntax:
MVN{<cond>}{S} <Rd>, <shifter_operand>
RTL:
if(cond)
Rd NOT shifter_operand
if(S==1 and Rd==R15)
CPSR SPSR
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 1 1 1 S SBZ Rd shifter operand
RTL:
if(cond)
Rd Rn OR shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 1 0 0 S Rn Rd shifter operand
Page 25
4.24 RSB – Reverse Subtract
Syntax:
RSB{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
RTL:
if(cond)
Rd shifter_operand - Rn
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 0 1 1 S Rn Rd shifter operand
RTL:
if(cond)
Rd shifter_operand – Rn – NOT C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 1 1 1 S Rn Rd shifter operand
Page 26
4.26 SBC – Subtract with Carry
Syntax:
SBC{<cond>}{S} <Rd>, <Rn>, <shifter_operand>
RTL:
if(cond)
Rd Rn - shifter_operand – NOT C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 1 1 0 S Rn Rd shifter operand
RTL:
if(cond)
Rd_MSW:Rd_LSW Rd_MSW:Rd_LSW + (Rs • Rm)
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 1 1 1 S Rd_MSW Rd_LSW Rs 1 0 0 1 Rm
Page 27
4.28 SMULL – Signed Multiply Long
Syntax:
SMULL{<cond>}{S} <Rd_LSW>, <Rd_MSW>, <Rm>, <Rs>
RTL:
if(cond)
Rd_MSW:Rd_LSW Rs • Rm
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 1 1 0 S Rd_MSW Rd_LSW Rs 1 0 0 1 Rm
RTL:
if(cond)
start_address Rn
for i = 0 to 15
if(register_list[i] == 1)
memory[next_address] Ri
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 0 0 P U 0 W 0 Rn register_list
Page 28
Usage and Examples:
The STM instruction permits block moves of registers to memory and enables efficient
stack operations. The registers may be listed in any order, but the registers are always
stored in order with the lowest numbered register going to the lowest memory address.
If Rn is also listed in the register list and register writeback (W bit) is set, the final value
stored for Rn can be unpredictable.
The addressing_mode field determines how next_address is calculated (bits P & W),
which control how the address is updated in conjunction with each register store. The
four addressing_mode values are;
IA - increment address by 4 after each load (post-increment)
IB - increment address by 4 before each load (pre-increment)
DA - decrement address by 4 after each load (post-decrement)
DB - decrement address by 4 before each load (pre-decrement)
The “!” following Rn controls the value of the writeback bit (bit W), and signifies that Rn
should be updated with the ending address at the end of the instruction. If the “!” is
not present (W=0), the value of Rn will be unchanged at the end of the instruction.
For use in conjunction with stack addressing, four alternative names can be used for
the addressing modes. See the LDM instruction for a detailed discussion and example of
usage.
Page 29
4.30 STR – Store Register
Syntax:
STR{<cond>} <Rd>, <addressing_mode>
RTL:
if(cond)
memory[memory_address] Rd
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 1 I P U 0 W 0 Rn Rd addressing_mode
RTL:
if(cond)
memory[memory_address] Rd[7:0]
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 1 I P U 1 W 0 Rn Rd addressing_mode
Page 30
4.32 STRH – Store Register Halfword
Syntax:
STRH{<cond>} <Rd>, <addressing_mode>
RTL:
if(cond)
memory[memory_address] Rd[15:0]
if(writeback)
Rn end_address
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 P U I W 0 Rn Rd addr_mode 1 0 1 1 addr_mode
RTL:
if(cond)
Rd Rn - shifter_operand
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 0 0 1 0 S Rn Rd shifter operand
Page 31
4.34 SWI – Software Interrupt
Syntax:
SWI{<cond>} <immediate_24>
RTL:
if(cond)
R14_svc address of next instruction after SWI instruction
SPSR_svc CPSR ; save current CPSR
CPSR[4:0] 10011b ; supervisor mode
CPSR[5] 0 ; ARM execution
CPSR[7] 1 ; disable interrupts
PC 0x00000008 ; jump to exception vector
Flags updated:
N/A
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 1 1 1 1 immediate_24
The 24-bit immediate value is ignored by the instruction, but the value in the instruction
can be determined by the exception handler if desired. Parameters can also be passed
to the SWI handler in general-purpose registers or memory locations.
RTL:
if(cond)
temp [Rn]
[Rn] Rm
Rd temp
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 1 0 0 0 0 Rn Rd SBZ 1 0 0 1 Rm
Page 32
Usage and Examples:
The SWP instruction exchanges a word between a register and memory. This
instruction is intended to support semaphore manipulation by completing the transfers
as a single, atomic operation.
ADR R1, semaphore ;semaphore address
MOV R0, #1
SWP R0, R0, [R1] ;make swap
CMPS R0, #0 ;test result
RTL:
if(cond)
temp [Rn]
[Rn] Rm
Rd temp
Flags updated:
None
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 1 0 1 0 0 Rn Rd SBZ 1 0 0 1 Rm
Page 33
4.37 TEQ – Test Equivalence
Syntax:
TEQ{<cond>} <Rn>, <shifter_operand>
RTL:
if(cond)
Rn XOR shifter_operand
Flags updated:
N, Z, C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 0 0 1 1 Rn Rd shifter operand
RTL:
if(cond)
Rn AND shifter_operand
Flags updated:
N, Z, C
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 I 1 0 0 0 1 Rn Rd shifter operand
Page 34
4.39 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)
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 1 0 1 S Rd_MSW Rd_LSW Rs 1 0 0 1 Rm
RTL:
if(cond)
Rd_MSW:Rd_LSW Rs • Rm
Encoding:
31 30 29 28 27 26 25 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
cond 0 0 0 0 1 0 0 S Rd_MSW Rd_LSW Rs 1 0 0 1 Rm
Page 35
5 Pseudo-Instructions
5.1 ADR – Load Address (short-range)
Syntax:
ADR{cond} <Rd>, <label>
Description:
The ADR pseudo-instruction assembles to a single ADD or SUB instruction, normally
with the PC as an operand. This produces position-independent code. The assembler
will report an error if it cannot create a valid instruction to load the address. If the label
is program-relative, it must be in the same assembler area as the ADR instruction. (The
ADRL pseudo-instruction can reach a wider address range.)
Description:
The ADRL pseudo-instruction will always generate a two-instruction sequence to load
the address of the given label into the destination register, giving it a wider target
range than the ADR instruction. The code is position-independent. The assembler will
report an error if it cannot create a valid instruction sequence. (The LDR pseudo-
instruction with a label argument can reach any address.)
Description:
ASR is a synonym for the MOV instruction with an ASR-shifted register operand. If an
immediate shift count is used, it is limited to the range 1-32. If Rm is not included, the
assembler will assume it is the same as Rd.
Page 36
5.4 LDR – Load Register
Syntax:
LDR{cond} <Rd>, =<expression>
LDR{cond} <Rd>, =<label-expression>
Description:
The LDR pseudo-instruction will generate an instruction to load the destination register
with the desired value.
The <expression> field must evaluate to a numeric constant. If the constant is an
allowable immediate expression (or the complement of one), a MOV or MVN instruction
will be generated. If it is not, the assembler will place the value in a memory location,
and generate a PC-relative load instruction to load it from that memory location.
If a label is specified, the assembler will generate a local memory location to store the
label address, and include the appropriate linker directives so that the correct address
will be in that location after linking.
Description:
LSL is a synonym for the MOV instruction with an LSL shifter operand. If an immediate
shift count is used, it is limited to the range 0-31. If Rm is not included, the assembler
will assume it is the same as Rd.
Description:
LSR is a synonym for the MOV instruction with an LSR shifter operand. If an immediate
shift count is used, it is limited to the range 1-32. If Rm is not included, the assembler
will assume it is the same as Rd.
Page 37
5.7 NOP – No Operation
Syntax:
NOP
Description:
There are numerous ways to encode a NOP (no operation) instruction for the
ARM7TDMI processor, such as adding 0 to a register, ORing a register with 0,
branching to the next instruction, etc. The actual encoding of the NOP is assembler-
dependent.
Description:
POP is a pseudonym for the LDMIA instruction, with R13! specified for the base register
(Rn). The PUSH/POP instructions assume a full-descending (FD) stack organization.
Description:
PUSH is a pseudonym for the STMDB instruction, with R13! specified for the base
register (Rn). The PUSH/POP instructions assume a full-descending (FD) stack
organization.
Page 38
5.11 RRX – Rotate Right with Extend
Syntax:
RRX{cond}{S} <Rd>, <Rm>
Description:
RRX is a synonym for the MOV instruction with an RRX shifter operand. If Rm is not
included, the assembler will assume it is the same as Rd.
Page 39