Professional Documents
Culture Documents
Lecture 7-ARM PDF
Lecture 7-ARM PDF
Thumb is:
Outline:
• a compressed, 16-bit representation of a
Î the Thumb programmers’ model subset of the ARM instruction set
• Thumb instructions – primarily to increase code density
• Thumb implementation – also increases performance in some cases
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 1 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 2
31 28 27 8 7 6 5 4 0 r0
shaded registers have
r1 restricted access
NZCV unused IF T mode
r2
r3
Lo registers
The ‘T’ bit in the CPSR controls the r4
r5
SP (r13)
– return symmetrically to ARM or Thumb code LR (r14)
CPSR
PC (r15)
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 3 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 4
• r14 is used as the link register • support for 8-bit byte, 16-bit half-word and
– implicitly, as in the ARM instruction set
32-bit data types
– half-words are aligned on 2-byte boundaries
• a few instructions can access r8 - r15
– words are aligned on 4-byte boundaries
• the CPSR flags are set by data processing
• 32-bit unsegmented memory
instructions & control conditional branches
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 5 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 6
1
The Thumb programmers’ model The Thumb instruction set
Thumb-ARM differences:
Outline:
• most Thumb instructions are unconditional
– all ARM instructions are conditional • the Thumb programmers’ model
• most Thumb instructions use a 2-address Î Thumb instructions
format • Thumb implementation
– most ARM instructions use a 3-address format
• Thumb applications
• Thumb instruction formats are less regular
– a result of the denser encoding
• Thumb has explicit shift opcodes
– ARM implements shifts as operand modifiers
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 7 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 8
15 12 11 8 7 0
These are similar to ARM instructions
1101 cond 8-bit offset (1) B<cond> <label> except:
15 11 10 0 • offsets are scaled to half-word, not word
11100 11-bit offset (2) B <label>
• range is reduced to fit into 16 bits
Some instructions (e.g. BL) work in two
15 12 11 10 0
1111 H 11-bit offset (3) BL <label>
15 7 6 5 3 2 0
stages
010001110 H Rm 000 (4) BX Rm
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 9 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 10
2
Thumb data processing instructions Thumb data processing instructions
15 10 9 8 6 5 3 2 0 15 10 9 6 5 3 2 0
000110 A Rm Rn Rd (1) ADD|SUB Rd,Rn,Rm 010000 Op Rm/Rs Rd/Rn (5) <Op> Rd/Rn,Rm/Rs
15 10 9 8 6 5 3 2 0 15 10 9 8 7 6 5 3 2 0
0 0 0 1 1 1 A #imm3 Rn Rd (2) ADD|SUB Rd,Rn,#imm3 010001 Op D M Rm Rd/Rn (6) ADD|CMP|MOV Rd/Rn,Rm
15 13 12 11 10 8 7 0 15 12 11 10 8 7 0
0 0 1 Op Rd/Rn #imm8 (3) <Op> R d/Rn ,#imm8 1010 R Rd #imm8 (7) ADD Rd,SP|PC,#imm8
15 13 12 11 10 6 5 3 2 0 15 8 7 6 0
0 0 0 Op #sh Rn Rd (4) LSL|LSR|ASR Rd,Rn,#shift 10110000 A #imm7 (8) ADD|SUB SP,SP,#imm7
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 13 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 14
Notes:
15 13 12 11 10 6 5 3 2 0
011 B L #off5 Rn Rd (1) LDR|STR{B} Rd,[Rn,#off5]
• in Thumb code shift operations are 15 12 11 10 6 5 3 2 0
separate from general ALU functions 1000 L #off5 Rn Rd (2) LDRH|STRH Rd,[Rn,#off5]
– in ARM code a shift can be combined with an
15 12 11 9 8 6 5 3 2 0
ALU function in a single instruction
0101 Op Rm Rn Rd (3) LDR|STR{S}{H|B} Rd,[Rn,Rm]
• all data processing operations on the ‘Lo’
15 11 10 8 7 0
registers set the condition codes 01001 Rd #off8 (4) LDR Rd,[PC,#off8]
– those on the ‘Hi’ registers do not, apart from
CMP which only changes the condition codes 15 12 11 10 8 7 0
1001 L Rd #off8 (5) LDR|STR Rd,[SP,#off8]
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 15 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 16
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 17 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 18
3
The Thumb instruction set Thumb instruction decompressor
B operand bus
Outline:
ARM instruction
data in immediate fields decoder
Thumb
Î Thumb implementation select high or
decompressor
low half-word
• Thumb applications mux
instruction
pipeline
31 28 27 26 25 24 21 20 19 16 15 12 11 0
1110 00 1 0100 1 0 Rd 0 Rd 0000 #imm8
©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 21 ©2001 PEVEIT Unit - ARM System Design Thumb – v4 - 22