Architecture, Programming and Development Tools
Architecture, Programming and Development Tools
Lesson 3 ARM CPU32 bit ARM and 16-bit Thumb Instruction Sets
Outline
Basic Features 32-bit Instruction Set Thumb 16-bit Instruction Set Inter-working with ARM/Thumb sets
ARM code size small than other RISCs 32-bit un-segmented memory
Basic Programming FeaturesProcessor can operate on the words as per initialization. A word alignment can in big endian [least significant byte stored as higher bits (address 3) of a word] or little endian [least significant byte stored as lower bits (address 0) of a word].
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 5
Data Types support 8-bit byte, 16-bit half-word data types half-words are aligned on 2byte boundaries 32-bit data types- words are aligned on 4-byte boundaries
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 6
Address
Half word
Address
Half word
Programming Model 16 general-purpose registers with program counter as one of the register (R15).
- Registers
R0 R1 R2 R3 R4 R5 R6 R7 Lo registers R8 R9 R10 R11 R12 Hi registers
SP (R13) Stack Pointer LR (R14) Link Register PC (Rr15) Program Counter CPSR SPSR
10
Outline
Basic Features 32-bit Instruction Set Thumb 16-bit Instruction Set Inter-working with ARM/Thumb sets
12
Load Instructions
LDM: Load multiple registers LDR: Load a register (32 bit) LDRB: Load a byte (8 bit) into register
13
LFM: Load multiple floating point values - ARM7500 LDRSB: Load a signed byte (8 bit) into register Load a half-word (16 bit) into register (in certain variants e.g. StrongARM)
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 14
Store Instructions
STM: Store multiple registers STR: Store a register (32 bit) STRB: Store a byte (8 bit) from a register
15
SFM: Store Multiple Floating point values- ARM7500 STRSB: Store a signed byte from a register- StrongARM STRSH: Store a signed half-word from a register- StrongARM
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 16
Load-store architecture Features LDM/STM with multiple options of addressing modes (like immediate) LDM/STM loads into a subset of registers in a list or save from the list to the memory addresses
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 17
Data Transfer Instructions MOV: Move value/register into a register MRC: Co-processor register transfer (co-processor to ARM) MVN: Move after negation
18
ADD
ADC
BIC
SBC and
A select Add with Carry bit clear Subtract with carry SUB: Subtract multiply long (32 x 32 64)
SUB
Arithmetic Instructions ADC: Add with Carry, ADD:Add SBC: Subtract with carry , SUB: Subtract RSC: Reverse Subtract with carry , RSB: Reverse Subtract BIC: A select bit Clear
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 20
21
AND
ORR
CMN
TEQ
EOR Exclusive OR
CMP
23
Logical Instructions.. Logical AND, ORR, EOR TST: Test bits (Hypothetical AND) TEQ: Test Equivalence (Hypothetical EOR) CMP: Compare values (Hypothetical SUB), CMN: Compare negated values
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 24
25
Lets the OS including Device Drivers, have a modular structure The code required to create a complete operating system spliced into a number of small parts (modules) and a module handler specifies by <number> The handler executes after passing any data through use of <suffix>
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 27
ARM32-bit Instruction Set Features Data processing, data transfer and control flow execute with several settable options Implementation of many instructions by just a few instructions at the set CPU instruction decoder decodes instruction as per chosen options
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005
28
ARM32-bit Instruction Option fields Conditional or no-condition 4-bit field inmost instructions - facilitates implementation of many conditional instructions After cond option, there are option fields like addressing mode, shift or rotate option, flag change fields
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 29
Bits 31-0
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 30
Instruction Format
cond 00 X opcode S Rn Rd operand 2 S specifies CPSR flags change or no change by the operation
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 31
If X =1 then b11-b8 specifies rotate right instruction and b7-b0 immediate operand. b11-b8 = 0000 means no rotation, b11-b8 = 0001 means rotate right 2 times, b11-b8 = 1111 means ROR 30 times. Immediate operand is32-bit with 24 msbs = 0s
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 32
Second source operand can also be shifted or rotated before using the source in the operations. Flags (N, Z, C and V)can be changed or unchanged as per S bit in the instruction. Move can be conditional or unconditional as per cond 4-bit field in the instruction
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 33
Outline
Basic Features 32-bit Instruction Set Thumb 16-bit Instruction Set Inter-working with ARM/Thumb sets
34
- Thumb16 bit subset Better code density than 32-bit architecture instruction set
35
Programming Model 8 general-purpose Lower set of registers permit 3-bit in the instruction for a register Program counter register (R15) Link Register (R14) Stack Pointer (R13)
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 36
16-bit Thumb Instruction Set Features Code size small than 32-bit instruction Most instructions - data processing, data transfer and control flow execute with nocondition field 3-bit for Lower set register facilitates implementation with 16-bit instruction
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 37
Instructions ExamplesLDMIA:Thumb: Store multiple registers LDR: Load register (32 bits?) LDRB:Load byte (8 bit) into register LDRH: Load half-word (!)into register
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 38
Contd
LDRSB: oad signed byte (sign + 7 bit) into registe LDRSH: Load signed half-word (sign + 15 bit) into register
39
Contd
STMIA:Thumb: Store multiple registers STR: Store register (32 bit?) STRB:Store byte (8 bit) STRH: Store half-word (16 bit)
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005
40
Data Transfer Instructions MOV: Move value/register into a register MVN: Move after negation PUSH: registers to stack POP: registers from stack
41
ADD
ADC
BIC
SBC and
MUL
NEG
A select Add with Carry bit clear Subtract with carry SUB: Subtract
SUB
42
AND
OR
CMN
CMP
EOR Exclusive OR
(Hypothetical SUB)
43
Program Flow Control NOP: No operation, B: Branch, BX: Branch and Exchange BL: Long Branch with Link (LR and PC exchange), BLX:Branch with Link and Exchange BKPT: Breakpoint
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 44
Instruction Example
ADD r4, #data8 16-bit instruction in memory decompressed at run time into 32-bit format will be 1110 (condition code) 011 01001 (minor opcode) 0 (S bit) 01000 (S bit) 0100 0000 (rotation) 1000 0000.
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 47
Outline
Basic Features 32-bit Instruction Set Thumb 16-bit Instruction Set Inter-working with ARM/Thumb sets
48
ARM/THUMB Inter-working
T-bit at CPSR support for interworking with 16-bit Thumb set and 32-bit ARM. T-bit in CPSR can always switch from ARM to Thumb and vice versa using assembly instruction code16 and code32, respectively.
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 49
When working with 16-bit Thumb set execute the instruction code16, T bit set in CPSR. When switching to 32-bit Arm set execute the instruction code32, reset T bit in CPSR.
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 50
ARM and Thumb code each execute in their own processor state as ARM PC increments by 4 and Thumb by 2
51
53
Summary
54
We learnt Programmability as little endian and big endian ARM 7 - Princeton architecture, ARM 9 Harvard architecture
8-bit byte, 16-bit half-word and 32-bit data types
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 55
We learnt Conditional data processing, data transfer and control flow Execution and addressing modes facilitate by the few instructions only
56
We learnt LDM/STM with many more addressing modes(like immediate) MAC Support
"Microcontrollers....", Raj Kamal, from Pearson Education, 2005 57
subset
Better code density than 32-bit architecture instruction set and switching in-between ARM 32-bit set and Thumb 16-bit set supported
58
59
THANK YOU
60