Transcript
7/28/2019 ARM7 TDMI Manual Pt3
1/46
ARM7TDMI Data SheetARM DDI 0029E
5-1
111
Open
Access
THUM B Instruc tion Se t
This chapter describes the THUMB instruction set.
Format Summary 5-2
Opcode Summary 5-3
5.1 Format 1: move shifted register 5-5
5.2 Format 2: add/subtract 5-7
5.3 Format 3: move/compare/add/subtract immediate 5-9
5.4 Format 4: ALU operations 5-115.5 Format 5: Hi register operations/branch exchange 5-13
5.6 Format 6: PC-relative load 5-16
5.7 Format 7: load/store with register offset 5-18
5.8 Format 8: load/store sign-extended byte/halfword 5-20
5.9 Format 9: load/store with immediate offset 5-22
5.10 Format 10: load/store halfword 5-24
5.11 Format 11: SP-relative load/store 5-26
5.12 Format 12: load address 5-28
5.13 Format 13: add offset to Stack Pointer 5-30
5.14 Format 14: push/pop registers 5-325.15 Format 15: multiple load/store 5-34
5.16 Format 16: conditional branch 5-36
5.17 Format 17: software interrupt 5-38
5.18 Format 18: unconditional branch 5-39
5.19 Format 19: long branch with link 5-40
5.20 Instruction Set Examples 5-42
5
7/28/2019 ARM7 TDMI Manual Pt3
2/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-2
Open
Access
Format Summary
The THUMB instruction set formats are shown in the following figure.
Figure 5-1: THUMB instruction set formats
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
1 0 0 0 Op Offset5 Rs Rd Move shifted register
2 0 0 0 1 1 I Op Rn/offset3 Rs Rd Add/subtract
3 0 0 1 Op Rd Offset8 Move/compare/add
/subtract immediate
4 0 1 0 0 0 0 Op Rs Rd ALU operations
5 0 1 0 0 0 1 Op H1 H2 Rs/Hs Rd/Hd Hi register operations
/branch exchange
6 0 1 0 0 1 Rd Word8 PC-relative load
7 0 1 0 1 L B 0 Ro Rb Rd Load/store with register
offset
8 0 1 0 1 H S 1 Ro Rb Rd Load/store sign-extended
byte/halfword
9 0 1 1 B L Offset5 Rb Rd Load/store with immediate
offset
10 1 0 0 0 L Offset5 Rb Rd Load/store halfword
11 1 0 0 1 L Rd Word8 SP-relative load/store
12 1 0 1 0 SP Rd Word8 Load address
13 1 0 1 1 0 0 0 0 S SWord7 Add offset to stack pointer
14 1 0 1 1 L 1 0 R Rlist Push/pop registers
15 1 1 0 0 L Rb Rlist Multiple load/store
16 1 1 0 1 Cond Soffset8 Conditional branch
17 1 1 0 1 1 1 1 1 Value8 Software Interrupt
18 1 1 1 0 0 Offset11 Unconditional branch
19 1 1 1 1 H Offset Long branch with link
15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0
7/28/2019 ARM7 TDMI Manual Pt3
3/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-3
Open
Access
Opcode Summary
The following table summarizes the THUMB instruction set. For further
information about a particular instruction please refer to the sections listed in theright-most column.
Mnemonic Instruction Lo register
operand
Hi register
operand
Condition
codes set
See Section:
ADC Add with Carry 5.4
ADD Add 5.1.3, 5.5, 5.12, 5.13
AND AND 5.4
ASR Arithmetic Shift Right 5.1, 5.4
B Unconditional branch 5.16
Bxx Conditional branch 5.17
BIC Bit Clear 5.4
BL Branch and Link 5.19
BX Branch and Exchange 5.5
CMN Compare Negative 5.4
CMP Compare 5.3, 5.4, 5.5
EOR EOR
5.4
LDMIA Load multiple 5.15
LDR Load word 5.7, 5.6, 5.9, 5.11
LDRB Load byte 5.7, 5.9
LDRH Load halfword 5.8, 5.10
LSL Logical Shift Left 5.1, 5.4
LDSB Load sign-extended
byte
5.8
LDSH Load sign-extended
halfword
5.8
LSR Logical Shift Right 5.1, 5.4
MOV Move register 5.3, 5.5
MUL Multiply 5.4
MVN Move Negative register 5.4
Table 5-1: THUMB instruction set opcodes
7/28/2019 ARM7 TDMI Manual Pt3
4/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-4
Open
Access
The condition codes are unaffected by the format 5, 12 and 13versions of this instruction.
The condition codes are unaffected by the format 5 version of thisinstruction.
NEG Negate 5.4
ORR OR 5.4
POP Pop registers 5.14
PUSH Push registers 5.14
ROR Rotate Right 5.4
SBC Subtract with Carry 5.4
STMIA Store Multiple 5.15
STR Store word 5.7, 5.9, 5.11
STRB Store byte 5.7
STRH Store halfword 5.8, 5.10
SWI Software Interrupt 5.17
SUB Subtract 5.1.3, 5.3
TST Test bits 5.4
Mnemonic Instruction Lo register
operand
Hi register
operand
Condition
codes set
See Section:
Table 5-1: THUMB instruction set opcodes (Continued)
7/28/2019 ARM7 TDMI Manual Pt3
5/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-5
Open
Access
5.1 Format 1: move shifted register
Figure 5-2: Format 1
5.1.1 Operation
These instructions move a shifted value between Lo registers. The THUMB assemblersyntax is shown in Table 5-2: Summary of format 1 instructions.
Note All instructions in this group set the CPSR condition codes.
OP THUMB assembler ARM equivalent Action
00 LSL Rd, Rs, #Offset5 MOVS Rd, Rs, LSL #Offset5 Shift Rs left by a 5-bit immediate value
and store the result in Rd.
01 LSR Rd, Rs, #Offset5 MOVS Rd, Rs, LSR #Offset5 Perform logical shift right on Rs by a 5-bit immediate value and store the result
in Rd.
10 ASR Rd, Rs, #Offset5 MOVS Rd, Rs, ASR #Offset5 Perform arithmetic shift right on Rs by a
5-bit immediate value and store the
result in Rd.
Table 5-2: Summary of format 1 instructions
0123456789101112131415
Offset5 Rs000
Destination register
Source register
Immediate value
Opcode
Op Rd
0 - LSL1 - LSR2 - ASR
7/28/2019 ARM7 TDMI Manual Pt3
6/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-6
Open
Access
5.1.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table
5-2: Summary of format 1 instructionson page 5-5. The instruction cycle times for theTHUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations.
5.1.3 Examples
LSR R2, R5, #27 ; Logical shift right the contents
; of R5 by 27 and store the result in R2.
; Set condition codes on the result.
7/28/2019 ARM7 TDMI Manual Pt3
7/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-7
Open
Access
5.2 Format 2: add/subtract
Figure 5-3: Format 2
5.2.1 Operation
These instructions allow the contents of a Lo register or a 3-bit immediate value to beadded to or subtracted from a Lo register. The THUMB assembler syntax is shown inTable 5-3: Summary of format 2 instructions.
Note All instructions in this group set the CPSR condition codes.
Op I THUMB assembler ARM equivalent Action
0 0 ADD Rd, Rs, Rn ADDS Rd, Rs, Rn Add contents of Rn to contents of Rs. Place
result in Rd.
0 1 ADD Rd, Rs, #Offset3 ADDS Rd, Rs, #Offset3 Add 3-bit immediate value to contents of
Rs. Place result in Rd.
1 0 SUB Rd, Rs, Rn SUBS Rd, Rs, Rn Subtract contents of Rn from contents of
Rs. Place result in Rd.
1 1 SUB Rd, Rs, #Offset3 SUBS Rd, Rs, #Offset3 Subtract 3-bit immediate value from
contents of Rs. Place result in Rd.
Table 5-3: Summary of format 2 instructions
0123456789101112131415
Rn/Offset3 Rs1000
Destination register
Opcode
Source register
0 - ADD
Register/
1 - SUB
Immediate value
Immediate flag0 - Register operand
1 - Immediate operand
1 I Op Rd
7/28/2019 ARM7 TDMI Manual Pt3
8/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-8
Open
Access
5.2.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table
5-3: Summary of format 2 instructionson page 5-7. The instruction cycle times for theTHUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations.
5.2.3 Examples
ADD R0, R3, R4 ; R0 := R3 + R4 and set condition codes on
; the result.
SUB R6, R2, #6 ; R6 := R2 - 6 and set condition codes.
7/28/2019 ARM7 TDMI Manual Pt3
9/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-9
Open
Access
5.3 Format 3: move/compare/add/subtract immediate
Figure 5-4: Format 3
5.3.1 Operations
The instructions in this group perform operations between a Lo register and an 8-bitimmediate value.
The THUMB assembler syntax is shown in Table 5-4: Summary of format 3instructions.
Note All instructions in this group set the CPSR condition codes.
Op THUMB assembler ARM equivalent Action
00 MOV Rd, #Offset8 MOVS Rd, #Offset8 Move 8-bit immediate value into Rd.
01 CMP Rd, #Offset8 CMP Rd, #Offset8 Compare contents of Rd with 8-bit
immediate value.
10 ADD Rd, #Offset8 ADDS Rd, Rd, #Offset8 Add 8-bit immediate value to contents of Rd
and place the result in Rd.
11 SUB Rd, #Offset8 SUBS Rd, Rd, #Offset8 Subtract 8-bit immediate value from
contents of Rd and place the result in Rd.
Table 5-4: Summary of format 3 instructions
0123456789101112131415
RdOp100 Offset8
Source/destination register
Immediate value
Opcode0 - MOV1 - CMP2 - ADD3 SUB
7/28/2019 ARM7 TDMI Manual Pt3
10/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-10
Open
Access
5.3.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table
5-4: Summary of format 3 instructionson page 5-9. The instruction cycle times for theTHUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations.
5.3.3 Examples
MOV R0, #128 ; R0 := 128 and set condition codes
CMP R2, #62 ; Set condition codes on R2 - 62
ADD R1, #255 ; R1 := R1 + 255 and set condition
; codes
SUB R6, #145 ; R6 := R6 - 145 and set condition
; codes
7/28/2019 ARM7 TDMI Manual Pt3
11/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-11
Open
Access
5.4 Format 4: ALU operations
Figure 5-5: Format 4
5.4.1 Operation
The following instructions perform ALU operations on a Lo register pair.
Note All instructions in this group set the CPSR condition codes.
OP THUMB assembler ARM equivalent Action
0000 AND Rd, Rs ANDS Rd, Rd, Rs Rd:= Rd AND Rs
0001 EOR Rd, Rs EORS Rd, Rd, Rs Rd:= Rd EOR Rs
0010 LSL Rd, Rs MOVS Rd, Rd, LSL Rs Rd := Rd > Rs
0100 ASR Rd, Rs MOVS Rd, Rd, ASR Rs Rd := Rd ASR Rs
0101 ADC Rd, Rs ADCS Rd, Rd, Rs Rd := Rd + Rs + C-bit
0110 SBC Rd, Rs SBCS Rd, Rd, Rs Rd := Rd - Rs - NOT C-bit
0111 ROR Rd, Rs MOVS Rd, Rd, ROR Rs Rd := Rd ROR Rs
1000 TST Rd, Rs TST Rd, Rs Set condition codes on Rd AND Rs
1001 NEG Rd, Rs RSBS Rd, Rs, #0 Rd = -Rs
Table 5-5: Summary of Format 4 instructions
0123456789101112131415
Op Rs010
Source/destination
Source register 2
Opcode
Rd
register
0 0 0
7/28/2019 ARM7 TDMI Manual Pt3
12/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-12
Open
Access
5.4.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table5-5: Summary of Format 4 instructionson page 5-11. The instruction cycle times forthe THUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations.
5.4.3 Examples
EOR R3, R4 ; R3 := R3 EOR R4 and set condition codes
ROR R1, R0 ; Rotate Right R1 by the value in R0, store
; the result in R1 and set condition codes
NEG R5, R3 ; Subtract the contents of R3 from zero,
; store the result in R5. Set condition codes
; ie R5 = -R3
CMP R2, R6 ; Set the condition codes on the result of
; R2 - R6
MUL R0, R7 ; R0 := R7 * R0 and set condition codes
1010 CMP Rd, Rs CMP Rd, Rs Set condition codes on Rd - Rs
1011 CMN Rd, Rs CMN Rd, Rs Set condition codes on Rd + Rs
1100 ORR Rd, Rs ORRS Rd, Rd, Rs Rd := Rd OR Rs
1101 MUL Rd, Rs MULS Rd, Rs, Rd Rd := Rs * Rd
1110 BIC Rd, Rs BICS Rd, Rd, Rs Rd := Rd AND NOT Rs
1111 MVN Rd, Rs MVNS Rd, Rs Rd := NOT Rs
OP THUMB assembler ARM equivalent Action
Table 5-5: Summary of Format 4 instructions (Continued)
7/28/2019 ARM7 TDMI Manual Pt3
13/46
7/28/2019 ARM7 TDMI Manual Pt3
14/46
7/28/2019 ARM7 TDMI Manual Pt3
15/46
7/28/2019 ARM7 TDMI Manual Pt3
16/46
7/28/2019 ARM7 TDMI Manual Pt3
17/46
7/28/2019 ARM7 TDMI Manual Pt3
18/46
7/28/2019 ARM7 TDMI Manual Pt3
19/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-19
Open
Access5.7.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table5-8: Summary of format 7 instructionson page 5-18. The instruction cycle times for theTHUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction Cycle
Operations.
5.7.3 Examples
STR R3, [R2,R6] ; Store word in R3 at the address
; formed by adding R6 to R2.
LDRB R2, [R0,R7] ; Load into R2 the byte found at
; the address formed by adding
; R7 to R0.
0 1 STRB Rd, [Rb, Ro] STRB Rd, [Rb, Ro] Pre-indexed byte store:
Calculate the target address byadding together the value in Rb
and the value in Ro. Store the byte
value in Rd at the resulting
address.
1 0 LDR Rd, [Rb, Ro] LDR Rd, [Rb, Ro] Pre-indexed word load:
Calculate the source address by
adding together the value in Rb
and the value in Ro. Load the
contents of the address into Rd.
1 1 LDRB Rd, [Rb, Ro] LDRB Rd, [Rb, Ro] Pre-indexed byte load:
Calculate the source address by
adding together the value in Rband the value in Ro. Load the byte
value at the resulting address.
L B THUMB assembler ARM equivalent Action
Table 5-8: Summary of format 7 instructions (Continued)
7/28/2019 ARM7 TDMI Manual Pt3
20/46
7/28/2019 ARM7 TDMI Manual Pt3
21/46
7/28/2019 ARM7 TDMI Manual Pt3
22/46
7/28/2019 ARM7 TDMI Manual Pt3
23/46
7/28/2019 ARM7 TDMI Manual Pt3
24/46
7/28/2019 ARM7 TDMI Manual Pt3
25/46
7/28/2019 ARM7 TDMI Manual Pt3
26/46
7/28/2019 ARM7 TDMI Manual Pt3
27/46
7/28/2019 ARM7 TDMI Manual Pt3
28/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-28
Open
Access
5.12 Format 12: load address
Figure 5-13: Format 12
5.12.1 Operation
These instructions calculate an address by adding an 10-bit constant to either the PCor the SP, and load the resulting address into a register.
The THUMB assembler syntax is shown in the following table.
Note The value specified by #Imm is a full 10-bit value, but this must be word-aligned (iewith bits 1:0 set to 0) since the assembler places #Imm >> 2 in field Word8.
Where the PC is used as the source register (SP = 0), bit 1 of the PC is always read
as 0. The value of the PC will be 4 bytes greater than the address of the instructionbefore bit 1 is forced to 0.
The CPSR condition codes are unaffected by these instructions.
SP THUMB assembler ARM equivalent Action
0 ADD Rd, PC, #Imm ADD Rd, R15, #Imm Add #Imm to the current value ofthe program counter (PC) and load
the result into Rd.
1 ADD Rd, SP, #Imm ADD Rd, R13, #Imm Add #Imm to the current value of
the stack pointer (SP) and load the
result into Rd.
Table 5-13: Load address
0123456789101112131415
Rd101 0 SP Word8
8-bit unsigned constant
Destination register
Source0 - PC1 - SP
7/28/2019 ARM7 TDMI Manual Pt3
29/46
7/28/2019 ARM7 TDMI Manual Pt3
30/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-30
Open
Access
5.13 Format 13: add offset to Stack Pointer
Figure 5-14: Format 13
5.13.1 Operation
This instruction adds a 9-bit signed constant to the stack pointer. The following tableshows the THUMB assembler syntax.
Note The offset specified by #Imm can be up to -/+ 508, but must be word-aligned (ie withbits 1:0 set to 0) since the assembler converts #Imm to an 8-bit sign + magnitudenumber before placing it in field SWord7.
Note The condition codes are not set by this instruction.
5.13.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table5-14: The ADD SP instructionon page 5-30. The instruction cycle times for theTHUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations
S THUMB assembler ARM equivalent Action
0 ADD SP, #Imm ADD R13, R13, #Imm Add #Imm to the stack pointer (SP).
1 ADD SP, #-Imm SUB R13, R13, #Imm Add #-Imm to the stack pointer (SP).
Table 5-14: The ADD SP instruction
0123456789101112131415
101 1
7-bit immediate value
SWord7000 0 S
Sign flag0 -Offset is positive1 -Offset is negative
7/28/2019 ARM7 TDMI Manual Pt3
31/46
7/28/2019 ARM7 TDMI Manual Pt3
32/46
7/28/2019 ARM7 TDMI Manual Pt3
33/46
7/28/2019 ARM7 TDMI Manual Pt3
34/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-34
Open
Access
5.15 Format 15: multiple load/store
Figure 5-16: Format 15
5.15.1 Operation
These instructions allow multiple loading and storing of Lo registers. The THUMBassembler syntax is shown in the following table.
5.15.2 Instruction cycle times
All instructions in this format have an equivalent ARM instruction as shown in Table5-16: The multiple load/store instructionson page 5-34. The instruction cycle times forthe THUMB instruction are identical to that of the equivalent ARM instruction. For moreinformation on instruction cycle times, please refer to Chapter 10, Instruction CycleOperations
L THUMB assembler ARM equivalent Action
0 STMIA Rb!, { Rlist } STMIA Rb!, { Rlist } Store the registers specified by
Rlist, starting at the base address
in Rb. Write back the new baseaddress.
1 LDMIA Rb!, { Rlist } LDMIA Rb!, { Rlist } Load the registers specified by
Rlist, starting at the base address
in Rb. Write back the new base
address.
Table 5-16: The multiple load/store instructions
0123456789101112131415
Rb011 0 L Rlist
Register list
Base register
Load/Store bit0 - Store to memory1 - Load from memory
7/28/2019 ARM7 TDMI Manual Pt3
35/46
7/28/2019 ARM7 TDMI Manual Pt3
36/46
THUM B Instruc tion Se t
ARM7TDMI Data SheetARM DDI 0029E
5-36
Open
Access
5.16 Format 16: conditional branch
Figure 5-17: Format 16
5.16.1 Operation
The instructions in this group all perform a conditional Branch depending on the stateof the CPSR condition codes. The branch offset must take account of the prefetchoperation, which causes the PC to be 1 word (4 bytes) ahead of the current instruction.
The THUMB assembler syntax is shown in the following table.
Cond THUMB assembler ARM equivalent Action
0000 BEQ label BEQ label Branch if Z set (equal)
0001 BNE label BNE label Branch if Z clear (not equal)
0010 BCS label BCS label Branch if C set (unsigned higher or
same)
0011 BCC label BCC label Branch if C clear (unsigned lower)
0100 BMI label BMI label Branch if N set (negative)
0101 BPL label BPL label Branch if N clear (positive or zero)
0110 BVS label BVS label Branch if V set (overflow)
0111 BVC label BVC label Branch if V clear (no overflow)
1000 BHI label BHI label Branch if C set and Z clear
(unsigned higher)
1001 BLS label BLS label Branch if C clear or Z set
(unsigned lower or same)
Table 5-17: The conditional branch instructions
0123456789101112131415
011 1
8-bit signed immediate
Condition
Cond SOffset8
7/28/2019 ARM7 TDMI Manual Pt3
37/46
7/28/2019 ARM7 TDMI Manual Pt3
38/46
7/28/2019 ARM7 TDMI Manual Pt3
39/46
7/28/2019 ARM7 TDMI Manual Pt3
40/46
7/28/2019 ARM7 TDMI Manual Pt3
41/46
7/28/2019 ARM7 TDMI Manual Pt3
42/46
7/28/2019 ARM7 TDMI Manual Pt3
43/46
7/28/2019 ARM7 TDMI Manual Pt3
44/46
7/28/2019 ARM7 TDMI Manual Pt3
45/46
7/28/2019 ARM7 TDMI Manual Pt3
46/46
top related