Upload
vuongnhi
View
223
Download
1
Embed Size (px)
Citation preview
1Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Microprocessor
and
Microcontroller
Architecture
2Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Von Neumann Architecture
Stored-Program Digital Computer
• Digital computation in ALU
• Programmable via set of standard instructions
• Internal storage of data
• Internal storage of program
• Automatic Input/Output
• Automatic sequencing of instruction execution bydecoder/controller
input memory output
controller
data/instruction path
control path
ArithmeticLogicUnit(ALU)
Von Neumann ArchitectureData and instructions stored in a single memory unit
Harvard ArchitectureData and instructions stored in a separate memory units
3Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Memory Hierarchy
Long TermStorage
Main Memory(RAM) Cache Register
All Filesand Data
Running Programsand Data
Next FewInstructionsand Data
CurrentData
μP: InternalμC: Virtual
μP: InternalμC: —
μP: ExternalμC: Internal
μP: ExternalμC: External
Access by nameWidth = word
Access by address Width = byte
Access by address Width = byte
Access by OS call Width = allocation unit
Fastest access to small amount of
data
Copy small section of Main Memory for faster access
"All" data and instructions of
running programs
Data and instructions of "all" programs
Levels of data / memory storage
4Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
μP Subsystems
main memorymemorycontrol
Main Memory Unitcache
memorycachecontrol
Cache Memory Unit
input
output
I/Ocontrol
I/O System
long‐termstorage
network
ArithmeticLogicUnit(ALU)
registermemory
processorcontrol
Microprocessor
Processor package
Bus Controller
5Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
μC Subsystems
input
output
long‐termstorage
I/O devices
ArithmeticLogicUnit(ALU)
datamemory
processorcontrol
Microprocessor
Controller package
timersinstructionmemory
6Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Instruction Set Architecture General instruction — instance of data structure
Instruction set Range of data structure for
Operation ∈ {legal actions}
Operand ∈ {legal addressing modes}
Machine instructionBinary code for processing by hardware
Assembly instructionUser-friendly form of machine instructionBinary code → words
Typical instructionMachine: 0x82E31F2B Assembly: ADD destination, source_1, source_2Definition: destination ← source_1 + source_2
Operand...OperandOperandOperation
7Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
General OperationsData transfer
Load (r ← m), store (m ← r), move (r/m ← r/m), convert data types
Arithmetic/Logical (ALU)Integer arithmetic (+ – × ÷ compare shift) and logical (AND, OR, NOR, XOR)
DecimalInteger arithmetic on decimal numbers
Floating point (FPU)Floating point arithmetic (+ – × ÷ sqrt trig exp …)
StringString move, string compare, string search
ControlConditional and unconditional branch, call/return, trap
Operating System System calls, virtual memory management instructions
GraphicsPixel operations, compression/decompression operations
8Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Immediate (IMM)Constant = literal = numerical value coded into instruction
Register operandsregister name = a μP storage locationREGS[register name] = data stored in registerREGS[R3] = data stored in register R3 = 11223340
Memory operandsaddress = a memory storage locationMEM[address] = data stored in memoryMEM[11223344] = data stored at address 11223344 = 45
Effective Address (EA) — pointer arithmeticREGS[R3] ← &(variable)MEM[REGS[R3]+4] = *(&(variable)+4) = *(REGS[R3]+4)
= *(11223340+4) = 45
Addressing Modes
11223340
R3
45
11223344
Formal specification
9Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
General Addressing Modes
Mode Syntax Memory Access Use Register R3 Regs[R3] Register data Immediate #3 3 Constant Direct (absolute) (1001) Mem[1001] Static data
Register deferred (R1) Mem[Regs[R1]] Pointer
Displacement 100(R1) Mem[100+Regs[R1]] Local variable Indexed (R1 + R2) Mem[Regs[R1]+Regs[R2]] Array addressing Memory indirect @(R3) Mem[Mem[Regs[R3]]] Pointer to pointer
Auto Increment (R2)+
Mem[Regs[R2]] Regs[R2] ← Regs[R2]+d Stack access
Auto Decrement -(R2)
Regs[R2] ← Regs[R2]-d Mem[Regs[R2]]
Stack access
Scaled 100(R2)[R3] Mem[100+Regs[R2]+Regs[R3]*d] Indexing arrays
PC-relative (PC) Mem[PC+value] Load instruction to data register
PC-relative deferred 1001(PC) Mem[PC+Mem[1001]] Load instruction to
data register
10Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Read Only Memory (ROM)Non-volatile memory
Permanent configuration data Device initialization code (FIRMWARE)Basic Input/Output System (BIOS)
ROM technologiesOTP (One-Time Programmable)
Cannot be changed after writing
EPROM (Erasable Programmable Read-Only Memory)Glass window allows ultraviolet light to erase device
EEPROM (Electrical Erasable Programmable Read-Only MemoryCan write electrically without prior erase
FlashOrganized as blocks
Copy block → delete entire block (write 0) → overwrite 1‐bits1 → 0
Overwrite and bit in any block0 → 1Write
Read any bit in any blockRead
11Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
General Register Operation ModelsRegister-Memory Model
Operands can be stored in any REGISTER or MEMORY locationZ = X + Y → load R1, X
add R1, R1, Ystore Z, R1
Easier to program
Register- Register ModelMEMORY operands must be loaded to a REGISTER
Also called LOAD-STORE MODELZ = X + Y → load R1, X
load R2, Yadd R1, R1, R2store Z, R1
Easier to implement in hardwareStatistics → most loaded operands used more than once
12Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Running Machine Language ProgramProgram list
Instruction 1Instruction 2Instruction 3Instruction 4Instruction 5Instruction 6
…
μPFetches next instruction in listDecodes fetched instructionExecutes decoded instruction Instruction 1
Instruction 2
Instruction 3
Instruction 4
Instruction 5
Abyte
A+1byte
A+2byte
A+3byte
A+4byte
A+5byte
A+6byte
A+7byte
A+8byte
A+9byte
A+10byte
A+11byte
Instructions in Flat Memory
Address
13Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Modular Programming (Main + Functions)Build program from separate source files (modules)
Each source module edited in a separate fileCompile / Assemble source files into separate object files
Object code is machine code with symbolic external referencesLink object files together
Create executable fileEasier to design, read and understand programs
Write most modules in high level language Write critical sections in assembly language Write, debug, and change modules independently
main.C
f1.ASM
f2.C
compile
assemble
compile
main.OBJ
f1.OBJ
f2.OBJ
f_std.LIB
link prog.EXE
load
14Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Computer Design Before 1990Limitations
Memory = expensiveRAM ~ $5000/MB wholesale in 1977
Compiler = badBad error messagingWeak optimizationEfficient code ⇒ write / optimize in assembly language
ImplicationsComplex Instruction Set Computer (CISC)Easier assembly programming
Closer to high level language
Powerful assembly language> 300 instructions > 12 addressing modes > 10 data types
Powerful instructions ⇒ fewer instructions ⇒ less memory
15Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
CISC Physical ImplementationMachine Language Instruction
SUB R1, R2, 100(R3)
Microcode Instruction Sequence (Microprogram)ALU_IN ← R3ALU ← 100ADDMAR ← OUTREADALU_IN ← MDRALU ← R2SUBR1 ← OUT
Main Memory
Registers
MAR MDR+PCIRDecoderStatusWord
Address Data PC - program counterIR - instruction register
MAR - memory address registerMDR - memory data register
ALU Subsystem
System Bus
INOUT
ALU Operat ion
1
23
A LU R esult F lag
control
16Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Run Time and Clock CyclesμP is timed by periodic signal called a clock
Clock Cycle time is measured in seconds per cycleInstruction requires 1 or more clock cycles to processClock Rate is cycles per second = Hz (Hertz)
Higher clock rate ⇒ shorter run timeMore clock cycles (at constant clock rate) ⇒ longer run time
Clock Cycles Per Instruction (CPI) = lines of microcode
clockcycle
clock cycles to run program seconds per clock cyclesclock cycles to run program
clock cycles per second
= ×
=
Run time
17Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
CISC LimitationsComplex microcode
Many instruction types ⇒ many microcode sequencesComplex operations ⇒ complex decoding and sequencing
Central bus organizationPermits atomic microcode operationsSystem bus ⇒ bottleneck
Microcode operations execute one-at-a-timeMachine instructions execute one-at-a-time
Microcode ⇒ several clock cycles to execute machine instruction
Memory access Instruction length
Non-uniform Depends on operation complexity
Multiple clock cycles to load instruction
18Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Computer Design Since 1990Technological developments
Price of RAM$5000 / MByte (1975) → $5 / MByte (1990) → $0.01 / MByte (2012)
Compilers Powerful + efficient + optimized
Reduced Instruction Set Computer (RISC) Speed up most common operationsFewer machine instructions with uniform instruction length (in bytes)Ignore performance degradation to other operationsSimpler hardware design
No microcode No system bus
All processors today use RISC technologyPure RISC (PowerPC, Sparc, MIPS, ARM, Arduino, PIC, …)RISC technology for CISC language (Pentium II – 4, Centrino, Core) Explicitly parallel RISC (Intel Itanium, IBM mainframes)
19Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Typical RISC InstructionsExample OperandsInstructionClass
PC ← PC + (Imm * (F2 = 0))Conditional Branch
R31 ← PC
PC ← PC + ImmRegister/Immediate
Branch & Link
PC ← R1RegisterBranch Register
PC ← PC + ImmImmediateBranch
Control
F1 ← (F2 ≠ F3)Test & Set
F1 ← F2 × F3Register/Register
+ – × ÷Float
R1 ← (R2 > R3)Register/RegisterTest & Set
R1 ← R2 ∧ R3
R1 ← R2 ∨ Imm
R1 ← R2 + R3
R1 ← R2 – Imm
[R2 + offset] ← R1
R1 ← [R2 + offset]
Logic∧ ∨ ⊕
Register/Register Register/Immediate
Arithmetic+ – × ÷
ALU
Store Integer / Float
LoadTransfer
20Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Typical RISC Pipeline
InstructionFetch
InstructionMemory
InstructionDecode
ExecuteData
MemoryAccess
DataMemory
WriteBack
Address Instruction Address Data
Stage 1IF
Stage 2ID
Stage 3EX
Stage 4MEM
Stage 5WB
1 2 3 4 5 6 7 8 I1 IF ID EX MEM WB I2 IF ID EX MEM WB I3 IF ID EX MEM WB I4 IF ID EX MEM WB I5 IF ID EX MEMI6 IF ID EX I7 IF ID I8 IF
clock cycle
21Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Microcontroller (μC) versus Microprocessor (μP)Microprocessor (μP) application
General purpose computerAccess + process data → data output
Computational powerProgramming generality Execution speed
Multiple processors for parallel processingEach μP handles thread
Microcontroller (μC) applicationEmbedded system
Control external hardware operations
Cost efficiencySmall number of program tasks stored in permanent memoryLowest possible cost
Multiple controllers for concurrent control problemsEach μC applied to small group of tasks
22Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Embedded‐Processor CoreProgrammable Logic Devices (PLD/FPGA)
Generic programmable integrated circuitsLarge array of digital circuit blocksUser defines logic blocks
Truth tablesBoolean functionsKarnaugh diagrams
User defines connections on programmable routing matrixDesign copied to ASIC for manufacture
ASIC — application specific integrated circuit
Embedded-processor core μP or μC available on chip as programmable logic blockLarge embedded system designed on single chip
μP or μC works with other digital system blocks
System on chip (SoC)
23Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Choosing a Microcontroller —Generic RequirementsOptimum device for given application
Device familyUniform ISA Different hardware resources
Internal resourcesInterruptsType + number of I/O lines (analog and digital)Size of program and data memory
Space optimizationSmallest footprint at reasonable cost
Low power consumptionBattery powers applications using microcontrollersSleep state while microcontroller idle
Copy protection Stored program protected against user reading
24Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Microcontroller ComponentsMicroprocessor core
Typically RISC-type μPMemory
ROM holds program (FIRMWARE)RAM / registers for data + configuration
Usually RAM < ROM
Timers Time internal / external eventsWatchdog — timeout resets system if code loop fails
Controller I/OInterrupt controller — external event grabs processor attention Analog ↔ digital converters (A/D and D/A)Digital signal processor (DSP)Serial ↔ parallel converters (UART)
Oscillator Generates clock signal to synchronize all internal operations
25Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Special Purpose RegistersInstruction register
Holds executing instructionProgram counter
Points to next instructionAccumulator
Associated with ALU operations One operand must be in ACCResult stored in ACC
Status register (flags)Set configurationResults of ALU operations
Data address register (DAR) Stores data memory addresses
Stack pointerPoints to last element pushed to stack
26Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Reset Initializes microcontroller
Sets PC to preset value (init address)Microcontroller starts executing commands from init address
Causes of resetPower up
Controller resets at startup
Manual reset Press reset button
Power-glitch resetDetect spike on power supply
Brown-out resetInput voltage drops below threshold
Watchdog timer (WDT)
27Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Power ConsumptionLow power consumption
Most microcontroller applications on battery power
Low power chip technologyComplementary metal-oxide semiconductor (CMOS)
Clock frequency Power consumed only on logic transition 1 ↔ 0 Higher clock frequency ⇒ more transitions /second ⇒ more power
Supply voltageHigher supply voltage ⇒ faster + higher power
Sleep stateStop clock ⇒ 0 transitions /second ⇒ no powerLeave low-power mode by external interrupt or reset
Key pressInterrupt
28Dr. Martin LandProcessor ArchitectureEmbedded Systems — Hadassah College — Spring 2012
Common Microcontrollers
eZ8/80/16 familiesZilog
TLCS familiesToshiba
TMS familiesTexas Instruments
ST familiesSTMicroelectronics
SPC familiesSony
COP familiesNational Semiconductor
PIC familiesMicrochip Technology
MCS‐48 (8048 family)
MCS‐51 (8051 family)
MCS‐96 (8096 family)
Intel
68HC00 family
DSP56800
MPC family
Freescale
AVR family
AT89 family (Intel 8051 architecture)
AT91 family (ARM architecture)
Atmel
PowerPCApplied Micro (was IBM)