Microsoft PowerPoint – Week 8 2021
Week 8
Outline
• No comment about mid‐sem until after replacement tests.
• Introduction to Computer Architecture
• Understand AVR architecture
• Understand AVR Execution Cycle
• Pipelining
• Understand the Stack
• Understanding instructions and using the AVR manual
• Understand how to write an assembly program.
Course plan
• First half (we’ve completed this):
• Basic digital system concepts.
• Encoding/number systems
• Combinational logic
• Sequential Logic
• Basic General Computer Concepts
• Memory
• Higher level computer architecture:
• Understand structure of computer system
• Gain ability to program any architecture
• Need to be confident with assembly
• Understand connection with programming language
• Arbitrarily chose AVR
Why AVR?
• AVR architecture is what we intended for you to use for your robot
• (In arduino)
Stuff to consider
• We consider AVR design decisions
• Not same for all processors
• Reasons?
Stuff to consider
• We consider AVR design decisions
• Not same for all processors
• Reasons?
• Size
• Power
• Performance
Stuff to consider
• We consider AVR design decisions
• Not same for all processors
• Reasons?
• Size
• Power
• Performance
• Mistakes!
Details on AVR
• Detailed instruction set:
• http://ww1.microchip.com/downloads/en/DeviceDoc/ATmega48A‐PA‐88A‐
PA‐168A‐PA‐328‐P‐DS‐DS40002061A.pdf
• (~700 pages)
• (Can be thousands for complex processors)
• Don’t memorise. Learn how to understand
• We study a subset of instructions
• Lots are similar between different processors
• (especially in similar class. ARM/Imagination)
Notes away. Get a blank sheet of
paper.
Draw me a microprocessor
Draw me a microprocessor
AVR Microprocessor walk through
Program memory
• What does it do?
• What operations does it perform?
• What are it’s properties?
Program memory
• What does it do?
• Store instructions
• What operations does it perform?
• Read /write
• What are it’s properties?
• Each cell is ?‐bit.
• Read/write is always ? bits
• Different to data memory
• 32KB memory. How many address bits?
Program memory
• What does it do?
• Store instructions
• What operations does it perform?
• Read /write
• What are it’s properties?
• Each cell is ?‐bit.
• Read/write is always ? bits
• Different to data memory
• 32KB memory. How many address bits?
• 2^15=32768
• 2 byte cells.
• Need address for each cell, not each byte => 2^14 ‐> 14 into PC
Program counter
• What is it?
• What type of digital circuit is it?
Program counter
• What does it do?
• (Think it’s like your finger holding a book open)
• Stores address of next instruction
• Increments when move to next instruction
• How much to increment by? +1, +2 (instructions are 16 bits)
• What type of digital circuit is it?
• Register
• Adder (conditional)
• Multiplexer
Register File
• What is it?
• What digital circuit is this?
Register File
• What is it?
• Tiny, local memory
• Temporary storage
• What digital circuit is this?
• 32 8‐bit Registers (r0 to r31)
Register File
• What are X,Y,Z?
Register File
• What are X,Y,Z?
• A design decision
• Enable 26,27 (x), 28,29 (y), 30,31 (z) to be 16‐bit manipulations
• Why?
• Useful for certain instructions
• Ld R2 X
Register File
• How many bits do you need to encode a register?
ALU
• What does it do?
ALU
• What does it do?
• Calculations
• Add/Sub/Conjunction/Negation…
• How many bits can it add?
ALU
• What does it do?
• Calculations
• Add/Sub/Conjunction/Negation…
• How many bits can it add?
• Tied to a register
Status Register
• What does it do?
Status Register
• What does it do?
Status Register
• What does it do?
• Stores flags of special conditions
• Zero/overflow
Status Register
• What does it do?
• Stores flags of special conditions
• Zero/overflow
• What does it listen to?
• How does it store info?
Status Register
• What does it do?
• Stores flags of special conditions
• Zero/overflow
• What does it listen to?
• ALU
• How does it store info?
• Enable signal.
Data memory
• What does it do?
• Does it store instructions?
• 2KB. How many address bits?
Data memory
• What does it do?
• Stores integers Arrays…
• Does it store instructions?
• No.
• 2KB. How many address bits?
• Needs 11.
• Actually has 12
• Pretend larger memory
• Gives 256 additional fake address
• Allows some faster operations.
Instruction register
• What does it do?
Instruction register
• What does it do?
• Remembers current instruction
Instruction register
• What does it do?
• Remembers current instruction
• Why 16 bit?
Instruction register
• What does it do?
• Remembers current instruction
• Why 16 bit?
• Most instructions need 16 bits.
Instruction decoder
• What does it do?
Instruction decoder
• What does it do
• Open instruction, decide what to do
• Controls rest of circuit
• Operation: Adding/subtracting
• Operands
• Where to write result
Instruction decoder
• Is it combinational/sequential circuit?
Instruction decoder
• Is it combinational/sequential circuit?
• You need to do different things at different times
Execution cycle
• Say I want to do the instruction:
• Add R0,R1
• What happens?
• What goes first?
AVR Microprocessor walk through
Activity 1
Pipelining
• Analogous to assembly line
Two stage pipeline
Activity 2
Long instructions
Stack
• What is the stack?
Stack
• What is the stack?
• Area in data memory
• Special position: stack pointer
• Top of stack
Push operation
• Read or write?
Push operation
• Increase or decrease stack pointer?
Push operation
• Increase or decrease stack pointer?
• ELEC1601 9601 – Discussion (edstem.org)
Pop
• Get data
• Take off stack
Stack
• push r1
• push r2
• push r3
• Do some other work with r1 to r3
• How do you get data back into r1 to r3?
Activity 3
You have to design a microprocessor.
What operations should it include?
https://padlet.com/davidboland/9lwthi7szl2kqcs3
Typical instructions
• Add/subtract
• Mov
• Load
• Store
• Compare
• Branch (conditional)
• Jump
• I/O
Common instructions
• Multiply
• Divide Boolean operations
Common instructions?
• Fused Multiply Add
• Floating‐point
More instructions
• SIMD
• Accumulate (parallel)
• Trigonometric
• Function evaluation
RISC vs CISC
• Add/subtract
• Mov
• Load
• Store
• Compare
• Branch (conditional)
• Jump
• I/O
• Multiply
• Divide
• Boolean operations
• Fused Multiply Add
• Floating‐point
• SIMD
• Accumulate (parallel)
• Trigonometric
• Function evaluation
Why RISC vs CISC
• RISC can do everything that CISC can do. Why not use sequence of
instructions?
CISC vs RISC
• Time to decode
• Succinct code
• Instruction Faster
• Bits/instruction
CISC vs RISC
• Time to decode
• Succinct code
• Instruction Faster
• Bits/instruction
• Faster code execution?
• Simpler compiler
Other differences? CISC OR RISC
• ADD R1 R2
• Vs
• ADD R1 R2 R3
Activity 1
Activity 2
AVR Instruction set:
• Full instruction set:
(http://ww1.microchip.com/downloads/en/DeviceDoc/Atmel‐0856‐
AVR‐Instruction‐Set‐Manual.pdf)
• Do not memorise!
• Know how to use
• Summary document
(https://canvas.sydney.edu.au/courses/17907/pages/week‐
8?module_item_id=577689)
• You get this in exam
Quick walk through of instructions
• EASY:
• Mov
• Arithmetic
• What happens with overflow?
• Logical
• Two 8‐bit AND. Meaning?
• LDI/STS
• PUSH/POP
• Easy‐ish:
• MUL/MULS
• Can there be overflow?
Reading the manual & understanding how it
runs
• ADD
• CPI
• (JUMP/Branch later)
Quick walk through of instructions
• Medium:
• LD/ST
Quick walk through of instructions
• LDI vs LDS how many memory accesses
Quick walk through of instructions
• LD
Quick walk through of instructions
• Harder:
• LSL/LSR
• ASR
• Why no ASL?
Jump/Branch
• Why need to JUMP/Branch?
Jump/Branch
• Why need to JUMP/Branch?
• Add R1 R2
• …
• Jump…
Jump/Branch
• Why need to JUMP/Branch?
• What does it do?
Jump/Branch
• Why need to JUMP/Branch?
• Add R1 R2
• …
• Jump…
• How to specify address:
• In data memory or program memory?
Jump/Branch
• Why need to JUMP/Branch?
• Add R1 R2
• …
• Jump…
• How to specify address:
• In data memory or program memory?
• How to specify in assembly:
Label_location: Add R8 R9
…
JMP label_location
Jump/Branch
• Why need to JUMP/Branch?
• Problems with JMP/Branch?
Program basics
• What is starting point of JAVA/C program?
Program basics
• What is starting point of JAVA/C program?
• Main method
• Can be member of class…
• How does assembly code start your program?
Program basics
• If in assembly you have the following line of code, what happens:
main: JMP main
Jump/Branch
• Branch:
• JUMP only if condition
• Why need it?
Jump/Branch
• What instruction needs to be executed before a branch?
Jump/Branch
• What instruction needs to be executed before a branch?
• How far can you branch?
Jump/Branch
• What instruction needs to be executed before a branch?
• How far can you branch?
• What does it do?
Jump/Branch
• How do I code:
• if A>B