SlideShare uma empresa Scribd logo
1 de 25
11
Lecture 8
The ARM Architecture
22
In this lecture
 Introduction
 ARM Programmer’s Model
 ARM Instruction Set
33
ARM Ltd
 Founded in November 1990
 Spun out of Acorn Computers
 Designs the ARM range of RISC processor
cores
 Licenses ARM core designs to semiconductor
partners who fabricate and sell to their
customers.
 ARM does not fabricate silicon itself
 Also develop technologies to assist with the
design-in of the ARM architecture
 Software tools, boards, debug hardware,
application software, bus architectures,
peripherals etc
44
Introduction
 Many devices are powered by ARM processors
 E.g.
 Samsung galaxy S4 ----- ARM Cortex-A15/Cortex-A7
 IPhone 4 -------- ARM Cortex-A8
 Ipad mini ------- ARM Cortex-A9
55
Introduction…cntd
 ARM is a Reduced Instruction Set Computer (RISC)
 A large uniform register file
 A load/store architecture
 Simple addressing modes
 Uniform and fixed-length instruction fields
 Some enhancements of ARM to basic RISC architecture
 Conditional execution of all instructions
 Load and store multiple instructions
 Variable cycle execution for certain instructions
 Thumb 16-bit instruction set
 Enhanced instructions (e.g. enhanced DSP instructions)
66
ARM Versions
77
ARM Core Block Diagram
88
ARM Registers
 General-purpose registers
 37 32-bit registers
 At any one time only 16 of these registers are visible (r0 – r15)
 Some of these registers have special functions
 Register r13 is used as stack pointer (sp)
 Register r14 is called the link register (lr) and is where the core puts
the return address whenever it calls a subroutine
 Register r15 is the program counter (pc) and contains the address of
the next instruction
 Program status registers
 Current Program Status Register (CPSR)
 Saved Program Status Register (SPSR)
99
 ARM has seven basic operating modes
 Each mode has access to its own stack space and a different subset
of registers
 Some operations can only be carried out in a privileged mode
ARM Processor Modes
Mode Description
Supervisor
(SVC)
Entered on reset and when a Supervisor call
instruction (SVC) is executed
Privileged
modes
FIQ
Entered when a high priority (fast) interrupt is
raised
IRQ Entered when a normal priority interrupt is raised
Abort Used to handle memory access violations
Undef Used to handle undefined instructions
System
Privileged mode using the same registers as User
mode
User
Mode under which most Applications / OS tasks
run
Unprivileged
mode
Exceptionmodes
1010
The ARM Register Set
r0
r1
r2
r3
r4
r5
r6
r7
r8
r9
r10
r11
r12
r15 (pc)
cpsr
r13 (sp)
r14 (lr)
User mode
spsr
r13 (sp)
r14 (lr)
IRQ FIQ
r8
r9
r10
r11
r12
r13 (sp)
r14 (lr)
spsr spsr
r13 (sp)
r14 (lr)
Undef
spsr
r13 (sp)
r14 (lr)
Abort
spsr
r13 (sp)
r14 (lr)
SVC
Current mode Banked out registers
ARM has 37 registers, all 32-bits long
A subset of these registers is accessible in
each mode
Note: System mode uses the User mode
register set.
SPSR registers are used to save CPSR
of previous mode
1111
CPSR Register
 Condition flags
 N = Negative result from ALU
 Z = Zero result from ALU
 C = ALU operation Carried out
 V = ALU operation oVerflowed
 Interrupt masks
 I Disables IRQ interrupt
 F Disables FRQ interrupt
 T = 1 indicates Thumb execution
 Mode bits determine the mode in
Which the processor operates
1212
ARM Exceptions
 Exception
 Any condition that needs to halt the normal sequential execution of
instructions
 Five types of exceptions in ARM
 Each exception changes the processor mode
 When an exception occurs it is handled by an exception handler routine
1313
Vector Table
Exception Handling
 When an exception occurs, the ARM:
 Copies CPSR into SPSR_<mode>
 Sets appropriate CPSR bits
 Change to ARM state
 Change to exception mode
 Disable interrupts (if appropriate)
 Stores the return address in LR_<mode>
 Sets PC to vector address
 To return, exception handler needs to:
 Restore CPSR from SPSR_<mode>
 Restore PC from LR_<mode>
This can only be done in ARM state.
Vector table can be at
0xFFFF0000 on ARM720T
and on ARM9/10 family devices
FIQ
IRQ
(Reserved)
Data Abort
Prefetch Abort
Software Interrupt
Undefined Instruction
Reset
0x1C
0x18
0x14
0x10
0x0C
0x08
0x04
0x00
1414
ARM Instruction Set
1515
Data Sizes and Instruction Sets
 The ARM is a 32-bit architecture.
 When used in relation to the ARM:
 Byte means 8 bits
 Halfword means 16 bits (two bytes)
 Word means 32 bits (four bytes)
 Most ARM’s implement two instruction sets
 32-bit ARM Instruction Set
 16-bit Thumb Instruction Set
 Jazelle cores can also execute Java bytecode (8-bit instructions)
16039v12
 When the processor is executing in ARM state:
 All instructions are 32 bits wide
 All instructions must be word aligned
 Therefore the pc value is stored in bits [31:2] with bits [1:0] undefined (as instruction
cannot be halfword or byte aligned)
 When the processor is executing in Thumb state:
 All instructions are 16 bits wide
 All instructions must be halfword aligned
 Therefore the pc value is stored in bits [31:1] with bit [0] undefined (as instruction
cannot be byte aligned)
 When the processor is executing in Jazelle state:
 All instructions are 8 bits wide
 Processor performs a word access to read 4 instructions at once
Program Counter (r15)
17039v12
 Different types of instructions
 Data processing instructions
 Load-store instructions
 Branch instructions
 Software interrupt instruction
 Program status register instructions
 Some unique features of arm ISA
 Conditional execution
 Barrel shifter
Instruction Set
1818
Data Processing Instructions
 Consist of :
 Arithmetic: ADD ADC SUB SBC RSB RSC
 Logical: AND ORR EOR BIC
 Comparisons: CMP CMN TST TEQ
 Data movement: MOV MVN
 These instructions only work on registers, NOT memory.
 Syntax:
<Operation>{<cond>}{S} Rd, Rn, Operand2
 Comparisons set flags only - they do not specify Rd
 Data movement does not specify Rn
 Second operand is sent to the ALU via a barrel shifter.
1919
 ARM instructions can be made to execute conditionally by postfixing them with the
appropriate condition code field.
 This improves code density and performance by reducing the number of
forward branch instructions.
CMP r3,#0 CMP r3,#0
BEQ skip ADDNE r0,r1,r2
ADD r0,r1,r2
skip
 By default, data processing instructions do not affect the condition code flags but
the flags can be optionally set by using “S”. CMP does not need “S”.
loop
…
SUBS r1,r1,#1
BNE loop if Z flag clear then branch
decrement r1 and set flags
Conditional Execution and Flags
2020
Condition Codes
Not equal
Unsigned higher or same
Unsigned lower
Minus
Equal
Overflow
No overflow
Unsigned higher
Unsigned lower or same
Positive or Zero
Less than
Greater than
Less than or equal
Always
Greater or equal
EQ
NE
CS/HS
CC/LO
PL
VS
HI
LS
GE
LT
GT
LE
AL
MI
VC
Suffix Description
Z=0
C=1
C=0
Z=1
Flags tested
N=1
N=0
V=1
V=0
C=1 & Z=0
C=0 or Z=1
N=V
N!=V
Z=0 & N=V
Z=1 or N=!V
 The possible condition codes are listed below
 Note AL is the default and does not need to be specified
2121
Conditional Execution Examples
if (r0 == 0)
{
r1 = r1 + 1;
}
else
{
r2 = r2 + 1;
}
C source code
 5 instructions
 5 words
 5 or 6 cycles
 3 instructions
 3 words
 3 cycles
CMP r0, #0
BNE else
ADD r1, r1, #1
B end
else
ADD r2, r2, #1
end
...
ARM instructions
unconditional
CMP r0, #0
ADDEQ r1, r1, #1
ADDNE r2, r2, #1
...
conditional
2222
More Examples
 Use a sequence of several conditional instructions
if (a==0) func(1);
CMP r0,#0
MOVEQ r0,#1
BLEQ func
 Set the flags, then use various condition codes
if (a==0) x=0;
if (a>0) x=1;
CMP r0,#0
MOVEQ r1,#0
MOVGT r1,#1
 Use conditional compare instructions
if (a==4 || a==10) x=0;
CMP r0,#4
CMPNE r0,#10
MOVEQ r1,#0
2323
The Barrel Shifter
DestinationCF 0 Destination CF
LSL : Logical Left Shift ASR: Arithmetic Right Shift
Multiplication by a power of 2 Division by a power of 2,
preserving the sign bit
Destination CF...0 Destination CF
LSR : Logical Shift Right ROR: Rotate Right
Division by a power of 2 Bit rotate with wrap around
from LSB to MSB
Destination
RRX: Rotate Right Extended
Single bit rotate with wrap around
from CF to MSB
CF
2424
Register, optionally with shift operation
 Shift value can either be:
 5 bit unsigned integer
 Specified in bottom byte of
another register.
 Used for multiplication by constant
e.g.
MOV r0,r1,LSL#2 (r0 = r1*4)
ADD r0, r1, r1, LSL#3
Result
Operand
1
Barrel
Shifter
Operand
2
ALU
Using a Barrel Shifter:The 2nd Operand
(r0 = r1+r1*8 = 9*r1)
2525
More Readings
 ARM System Developer’s Guide (chapters 2 & 3)
 ARM Architecture Reference Manual

Mais conteúdo relacionado

Mais procurados (20)

Introduction to arm processor
Introduction to arm processorIntroduction to arm processor
Introduction to arm processor
 
80486 and pentium
80486 and pentium80486 and pentium
80486 and pentium
 
System On Chip (SOC)
System On Chip (SOC)System On Chip (SOC)
System On Chip (SOC)
 
2 introduction to arm architecture
2 introduction to arm architecture2 introduction to arm architecture
2 introduction to arm architecture
 
Unit 3
Unit 3Unit 3
Unit 3
 
Arm Processors Architectures
Arm Processors ArchitecturesArm Processors Architectures
Arm Processors Architectures
 
Serial Communication In Atmega 16
Serial Communication In Atmega 16Serial Communication In Atmega 16
Serial Communication In Atmega 16
 
Intel+80286
Intel+80286Intel+80286
Intel+80286
 
Part I:Introduction to assembly language
Part I:Introduction to assembly languagePart I:Introduction to assembly language
Part I:Introduction to assembly language
 
Introduction to arm architecture
Introduction to arm architectureIntroduction to arm architecture
Introduction to arm architecture
 
ARM Processor
ARM ProcessorARM Processor
ARM Processor
 
80386 processor
80386 processor80386 processor
80386 processor
 
8051 memory
8051 memory8051 memory
8051 memory
 
Microprocessor - Intel Pentium Series
Microprocessor - Intel Pentium SeriesMicroprocessor - Intel Pentium Series
Microprocessor - Intel Pentium Series
 
ARM
ARMARM
ARM
 
M6800
M6800M6800
M6800
 
Memory organization of 8051
Memory organization of 8051Memory organization of 8051
Memory organization of 8051
 
4.programmable dma controller 8257
4.programmable dma controller 82574.programmable dma controller 8257
4.programmable dma controller 8257
 
Msp 430 module 3
Msp 430 module 3Msp 430 module 3
Msp 430 module 3
 
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
Embedded Systems (18EC62) - ARM Cortex-M3 Instruction Set and Programming (Mo...
 

Semelhante a Lecture8 (20)

Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
Arm teaching material
Arm teaching materialArm teaching material
Arm teaching material
 
The ARM Architecture: ARM : ARM Architecture
The ARM Architecture: ARM : ARM ArchitectureThe ARM Architecture: ARM : ARM Architecture
The ARM Architecture: ARM : ARM Architecture
 
Arm
ArmArm
Arm
 
ARM.ppt
ARM.pptARM.ppt
ARM.ppt
 
Unit 4 _ ARM Processors .pptx
Unit 4 _ ARM Processors .pptxUnit 4 _ ARM Processors .pptx
Unit 4 _ ARM Processors .pptx
 
ARM Introduction
ARM IntroductionARM Introduction
ARM Introduction
 
arm-intro.ppt
arm-intro.pptarm-intro.ppt
arm-intro.ppt
 
07-arm_overview.ppt
07-arm_overview.ppt07-arm_overview.ppt
07-arm_overview.ppt
 
07-arm_overview.ppt
07-arm_overview.ppt07-arm_overview.ppt
07-arm_overview.ppt
 
LPC 2148 Instructions Set.ppt
LPC 2148 Instructions Set.pptLPC 2148 Instructions Set.ppt
LPC 2148 Instructions Set.ppt
 
Arm architecture
Arm architectureArm architecture
Arm architecture
 
Arm architecture overview
Arm architecture overviewArm architecture overview
Arm architecture overview
 
ARMInst.ppt
ARMInst.pptARMInst.ppt
ARMInst.ppt
 
ARMInst.ppt
ARMInst.pptARMInst.ppt
ARMInst.ppt
 
ESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparationESD_05_ARM_Instructions set for preparation
ESD_05_ARM_Instructions set for preparation
 
ARM Micro-controller
ARM Micro-controllerARM Micro-controller
ARM Micro-controller
 
Arm corrected ppt
Arm corrected pptArm corrected ppt
Arm corrected ppt
 
arm
armarm
arm
 
Lecture9
Lecture9Lecture9
Lecture9
 

Mais de misgina Mengesha (16)

Lecture6
Lecture6Lecture6
Lecture6
 
Lecture5
Lecture5Lecture5
Lecture5
 
Lecture5(1)
Lecture5(1)Lecture5(1)
Lecture5(1)
 
Lecture4
Lecture4Lecture4
Lecture4
 
Lecture3
Lecture3Lecture3
Lecture3
 
Lecture2
Lecture2Lecture2
Lecture2
 
Lecture1
Lecture1Lecture1
Lecture1
 
Sprabq8
Sprabq8Sprabq8
Sprabq8
 
Sensors2006
Sensors2006Sensors2006
Sensors2006
 
Sensors31
Sensors31Sensors31
Sensors31
 
Sensing for robotics and control s set13
Sensing for robotics and control s set13Sensing for robotics and control s set13
Sensing for robotics and control s set13
 
Introduction to sensors
Introduction to sensorsIntroduction to sensors
Introduction to sensors
 
Cn3 sensors and transducers-12
Cn3 sensors and transducers-12Cn3 sensors and transducers-12
Cn3 sensors and transducers-12
 
Cn3 sensors and transducers-1
Cn3 sensors and transducers-1Cn3 sensors and transducers-1
Cn3 sensors and transducers-1
 
480 sensors
480 sensors480 sensors
480 sensors
 
Wwwwww
WwwwwwWwwwww
Wwwwww
 

Lecture8

  • 1. 11 Lecture 8 The ARM Architecture
  • 2. 22 In this lecture  Introduction  ARM Programmer’s Model  ARM Instruction Set
  • 3. 33 ARM Ltd  Founded in November 1990  Spun out of Acorn Computers  Designs the ARM range of RISC processor cores  Licenses ARM core designs to semiconductor partners who fabricate and sell to their customers.  ARM does not fabricate silicon itself  Also develop technologies to assist with the design-in of the ARM architecture  Software tools, boards, debug hardware, application software, bus architectures, peripherals etc
  • 4. 44 Introduction  Many devices are powered by ARM processors  E.g.  Samsung galaxy S4 ----- ARM Cortex-A15/Cortex-A7  IPhone 4 -------- ARM Cortex-A8  Ipad mini ------- ARM Cortex-A9
  • 5. 55 Introduction…cntd  ARM is a Reduced Instruction Set Computer (RISC)  A large uniform register file  A load/store architecture  Simple addressing modes  Uniform and fixed-length instruction fields  Some enhancements of ARM to basic RISC architecture  Conditional execution of all instructions  Load and store multiple instructions  Variable cycle execution for certain instructions  Thumb 16-bit instruction set  Enhanced instructions (e.g. enhanced DSP instructions)
  • 8. 88 ARM Registers  General-purpose registers  37 32-bit registers  At any one time only 16 of these registers are visible (r0 – r15)  Some of these registers have special functions  Register r13 is used as stack pointer (sp)  Register r14 is called the link register (lr) and is where the core puts the return address whenever it calls a subroutine  Register r15 is the program counter (pc) and contains the address of the next instruction  Program status registers  Current Program Status Register (CPSR)  Saved Program Status Register (SPSR)
  • 9. 99  ARM has seven basic operating modes  Each mode has access to its own stack space and a different subset of registers  Some operations can only be carried out in a privileged mode ARM Processor Modes Mode Description Supervisor (SVC) Entered on reset and when a Supervisor call instruction (SVC) is executed Privileged modes FIQ Entered when a high priority (fast) interrupt is raised IRQ Entered when a normal priority interrupt is raised Abort Used to handle memory access violations Undef Used to handle undefined instructions System Privileged mode using the same registers as User mode User Mode under which most Applications / OS tasks run Unprivileged mode Exceptionmodes
  • 10. 1010 The ARM Register Set r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r15 (pc) cpsr r13 (sp) r14 (lr) User mode spsr r13 (sp) r14 (lr) IRQ FIQ r8 r9 r10 r11 r12 r13 (sp) r14 (lr) spsr spsr r13 (sp) r14 (lr) Undef spsr r13 (sp) r14 (lr) Abort spsr r13 (sp) r14 (lr) SVC Current mode Banked out registers ARM has 37 registers, all 32-bits long A subset of these registers is accessible in each mode Note: System mode uses the User mode register set. SPSR registers are used to save CPSR of previous mode
  • 11. 1111 CPSR Register  Condition flags  N = Negative result from ALU  Z = Zero result from ALU  C = ALU operation Carried out  V = ALU operation oVerflowed  Interrupt masks  I Disables IRQ interrupt  F Disables FRQ interrupt  T = 1 indicates Thumb execution  Mode bits determine the mode in Which the processor operates
  • 12. 1212 ARM Exceptions  Exception  Any condition that needs to halt the normal sequential execution of instructions  Five types of exceptions in ARM  Each exception changes the processor mode  When an exception occurs it is handled by an exception handler routine
  • 13. 1313 Vector Table Exception Handling  When an exception occurs, the ARM:  Copies CPSR into SPSR_<mode>  Sets appropriate CPSR bits  Change to ARM state  Change to exception mode  Disable interrupts (if appropriate)  Stores the return address in LR_<mode>  Sets PC to vector address  To return, exception handler needs to:  Restore CPSR from SPSR_<mode>  Restore PC from LR_<mode> This can only be done in ARM state. Vector table can be at 0xFFFF0000 on ARM720T and on ARM9/10 family devices FIQ IRQ (Reserved) Data Abort Prefetch Abort Software Interrupt Undefined Instruction Reset 0x1C 0x18 0x14 0x10 0x0C 0x08 0x04 0x00
  • 15. 1515 Data Sizes and Instruction Sets  The ARM is a 32-bit architecture.  When used in relation to the ARM:  Byte means 8 bits  Halfword means 16 bits (two bytes)  Word means 32 bits (four bytes)  Most ARM’s implement two instruction sets  32-bit ARM Instruction Set  16-bit Thumb Instruction Set  Jazelle cores can also execute Java bytecode (8-bit instructions)
  • 16. 16039v12  When the processor is executing in ARM state:  All instructions are 32 bits wide  All instructions must be word aligned  Therefore the pc value is stored in bits [31:2] with bits [1:0] undefined (as instruction cannot be halfword or byte aligned)  When the processor is executing in Thumb state:  All instructions are 16 bits wide  All instructions must be halfword aligned  Therefore the pc value is stored in bits [31:1] with bit [0] undefined (as instruction cannot be byte aligned)  When the processor is executing in Jazelle state:  All instructions are 8 bits wide  Processor performs a word access to read 4 instructions at once Program Counter (r15)
  • 17. 17039v12  Different types of instructions  Data processing instructions  Load-store instructions  Branch instructions  Software interrupt instruction  Program status register instructions  Some unique features of arm ISA  Conditional execution  Barrel shifter Instruction Set
  • 18. 1818 Data Processing Instructions  Consist of :  Arithmetic: ADD ADC SUB SBC RSB RSC  Logical: AND ORR EOR BIC  Comparisons: CMP CMN TST TEQ  Data movement: MOV MVN  These instructions only work on registers, NOT memory.  Syntax: <Operation>{<cond>}{S} Rd, Rn, Operand2  Comparisons set flags only - they do not specify Rd  Data movement does not specify Rn  Second operand is sent to the ALU via a barrel shifter.
  • 19. 1919  ARM instructions can be made to execute conditionally by postfixing them with the appropriate condition code field.  This improves code density and performance by reducing the number of forward branch instructions. CMP r3,#0 CMP r3,#0 BEQ skip ADDNE r0,r1,r2 ADD r0,r1,r2 skip  By default, data processing instructions do not affect the condition code flags but the flags can be optionally set by using “S”. CMP does not need “S”. loop … SUBS r1,r1,#1 BNE loop if Z flag clear then branch decrement r1 and set flags Conditional Execution and Flags
  • 20. 2020 Condition Codes Not equal Unsigned higher or same Unsigned lower Minus Equal Overflow No overflow Unsigned higher Unsigned lower or same Positive or Zero Less than Greater than Less than or equal Always Greater or equal EQ NE CS/HS CC/LO PL VS HI LS GE LT GT LE AL MI VC Suffix Description Z=0 C=1 C=0 Z=1 Flags tested N=1 N=0 V=1 V=0 C=1 & Z=0 C=0 or Z=1 N=V N!=V Z=0 & N=V Z=1 or N=!V  The possible condition codes are listed below  Note AL is the default and does not need to be specified
  • 21. 2121 Conditional Execution Examples if (r0 == 0) { r1 = r1 + 1; } else { r2 = r2 + 1; } C source code  5 instructions  5 words  5 or 6 cycles  3 instructions  3 words  3 cycles CMP r0, #0 BNE else ADD r1, r1, #1 B end else ADD r2, r2, #1 end ... ARM instructions unconditional CMP r0, #0 ADDEQ r1, r1, #1 ADDNE r2, r2, #1 ... conditional
  • 22. 2222 More Examples  Use a sequence of several conditional instructions if (a==0) func(1); CMP r0,#0 MOVEQ r0,#1 BLEQ func  Set the flags, then use various condition codes if (a==0) x=0; if (a>0) x=1; CMP r0,#0 MOVEQ r1,#0 MOVGT r1,#1  Use conditional compare instructions if (a==4 || a==10) x=0; CMP r0,#4 CMPNE r0,#10 MOVEQ r1,#0
  • 23. 2323 The Barrel Shifter DestinationCF 0 Destination CF LSL : Logical Left Shift ASR: Arithmetic Right Shift Multiplication by a power of 2 Division by a power of 2, preserving the sign bit Destination CF...0 Destination CF LSR : Logical Shift Right ROR: Rotate Right Division by a power of 2 Bit rotate with wrap around from LSB to MSB Destination RRX: Rotate Right Extended Single bit rotate with wrap around from CF to MSB CF
  • 24. 2424 Register, optionally with shift operation  Shift value can either be:  5 bit unsigned integer  Specified in bottom byte of another register.  Used for multiplication by constant e.g. MOV r0,r1,LSL#2 (r0 = r1*4) ADD r0, r1, r1, LSL#3 Result Operand 1 Barrel Shifter Operand 2 ALU Using a Barrel Shifter:The 2nd Operand (r0 = r1+r1*8 = 9*r1)
  • 25. 2525 More Readings  ARM System Developer’s Guide (chapters 2 & 3)  ARM Architecture Reference Manual