computer architecture - the simplest processor - cwi
TRANSCRIPT
![Page 1: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/1.jpg)
Computer architectureThe simplest processor
Wouter M. Koolen
Advanced Topics23-2-12
![Page 2: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/2.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
About me
I Work in machine learning ...
I .. but generally interested in most of computer science
I Fervent programmer
I Computer architecture as a hobby
I Author of SIM-PL simulator for digital hardware
http://www.science.uva.nl/amstel/SIM-PL
![Page 3: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/3.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Source material
![Page 4: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/4.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
What do I expect of you / What would really help
You ...
I want to learn
I have seen a digital circuit (e.g. gate, adder, flip-flop).
I wrote a program (e.g. if, goto, increment)
I are not mortally afraid of bits and hexadecimal
I ...
I will provide trick questions to guide your thinking
And most importantly ...
You raise your hand when you get lost
![Page 5: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/5.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
What do I expect of you / What would really help
You ...
I want to learn
I have seen a digital circuit (e.g. gate, adder, flip-flop).
I wrote a program (e.g. if, goto, increment)
I are not mortally afraid of bits and hexadecimal
I ...
I will provide trick questions to guide your thinking
And most importantly ...
You raise your hand when you get lost
![Page 6: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/6.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
What do I expect of you / What would really help
You ...
I want to learn
I have seen a digital circuit (e.g. gate, adder, flip-flop).
I wrote a program (e.g. if, goto, increment)
I are not mortally afraid of bits and hexadecimal
I ...
I will provide trick questions to guide your thinking
And most importantly ...
You raise your hand when you get lost
![Page 7: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/7.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Goal of this lecture
I present the simplest processor
UnderstandingI hardware design
I You can do it tooI Baseline for more complex designsI Many (esoteric) designs found niches
I execution of softwareI Programming (e.g. embedded devices)I Compiler architectureI The why of hardware eccentricities
![Page 8: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/8.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Goal of this lecturePierce layers of abstraction
Transistor
Gate
Boolean circuit
Arithmetic circuit
Stateful circuit
Memory
Calculator
Processor
Assembly language
C
Assembler
Compiler
![Page 9: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/9.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Calculator
Goal
I 16 variables (memory cells)
I program (list of instructions)
I 4 operations
Instruction setADD, SUB, AND, COPY
Example program0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 − Reg42: COPY $8, $6 Set Reg8 to Reg6
![Page 10: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/10.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Calculator
Goal
I 16 variables (memory cells)
I program (list of instructions)
I 4 operations
Instruction setADD, SUB, AND, COPY
Example program0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 − Reg42: COPY $8, $6 Set Reg8 to Reg6
![Page 11: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/11.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Calculator
Goal
I 16 variables (memory cells)
I program (list of instructions)
I 4 operations
Instruction setADD, SUB, AND, COPY
Example program0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 − Reg42: COPY $8, $6 Set Reg8 to Reg6
![Page 12: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/12.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Implementation: the hardware circuit
![Page 13: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/13.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
The driving force
Purpose: Synchronise operation of components
I Usually some kind of oscillating crystal
I Clock
I High and low levels
I Positive (up) edge and negative (down) edge
I A clock cycle is: up – high – down – low
![Page 14: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/14.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Program counter
Purpose: maintain the current position in the program
I One address
I Increment triggered by positive clock edge
![Page 15: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/15.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Instruction memory
Purpose: store the program
I 16 bit address
I 14 bit data
![Page 16: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/16.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
RegistersPurpose: maintain the state of program variables
I 16 registers named $0, $1, ..., $15I 16 bits eachI Two read portsI One write port (triggered by negative clock edge)
![Page 17: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/17.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Arithmetic logic unit (ALU)
Purpose: performs computation
S0 S1 output
0 0 A + B0 1 A− B1 0 A & B1 1 B
I 2 bits to select operation
![Page 18: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/18.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Calculator: the circuit
![Page 19: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/19.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
In action
Say $3 initially contains 7, while $4 contains 5.
0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 - Reg42: COPY $8, $6 Set Reg8 to Reg6
FFFF
FFFF
FFFF
FFFF
F
F
F
FFFF 3FFF
1
1
1
1
![Page 20: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/20.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
In action
Say $3 initially contains 7, while $4 contains 5.
0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 - Reg42: COPY $8, $6 Set Reg8 to Reg6
000C
000C
0007
0005
3
4
6
0000 0346
0
0
0
0
![Page 21: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/21.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
In action
Say $3 initially contains 7, while $4 contains 5.
0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 - Reg42: COPY $8, $6 Set Reg8 to Reg6
0002
0002
0007
0005
3
4
7
0001 1347
0
0
1
1
![Page 22: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/22.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
In action
Say $3 initially contains 7, while $4 contains 5.
0: ADD $6, $3, $4 Set Reg6 to Reg3 + Reg41: SUB $7, $3, $4 Set Reg7 to Reg3 - Reg42: COPY $8, $6 Set Reg8 to Reg6
000C
000C
FFFF
000C
0
6
8
0002 3068
1
1
1
1
![Page 23: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/23.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Summary
Calculator
I 16 memory cells
I 4 operations
I Executes program (list of instructions) sequentially
I Timing
![Page 24: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/24.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
(Trick) questions
I Why does an instruction take 14 bits of memory?
I Is COPY $1, $1 safe?
I What about ADD $1, $1, $1?
I Can we increment a register? How?
I Can we multiply 2 registers? How?
I Can we execute an if statement? How?
![Page 25: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/25.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates
GoalUse of immediates (constants) in instructions
Instruction setADD, SUB, AND, COPY, ADDI, SUBI, ANDI, LOADI
Example program0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
![Page 26: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/26.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates
GoalUse of immediates (constants) in instructions
Instruction setADD, SUB, AND, COPY, ADDI, SUBI, ANDI, LOADI
Example program0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
![Page 27: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/27.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates
GoalUse of immediates (constants) in instructions
Instruction setADD, SUB, AND, COPY, ADDI, SUBI, ANDI, LOADI
Example program0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
![Page 28: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/28.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Implementing immediates
Do we use an immediate?Immediate value
![Page 29: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/29.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Multiplexer
Purpose: channel chooser
S output
0 A1 B
I 1 bit to select which input is passed on
![Page 30: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/30.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates in action
0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
0
FFFF
FFFF
F
F
F
FFFF 7FFFFFFF
FFFFFFFF
FFFF
FFFF
FFFF
1
1
3
3
![Page 31: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/31.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates in action
0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
0
3000
3000
0
0
1
0000 30013000
FFFF3000
FFFF
3000
3000
0
0
3
3
![Page 32: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/32.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates in action
0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
0
2000
2000
0
0
2
0001 30022000
FFFF2000
FFFF
2000
2000
0
0
3
3
![Page 33: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/33.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates in action
0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
0
1000
1000
1
2
3
0002 51230000
20002000
3000
0000
0000
1
1
1
1
![Page 34: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/34.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Immediates in action
0: LOADI $1, 0x3000 Load 3000hex in Reg11: LOADI $2, 0x2000 Load 2000hex in Reg22: SUB $3, $1, $2 Set Reg3 to Reg1 - Reg23: ADDI $4, $3, 0x200 Set Reg4 to Reg3 + 0200hex
0
1200
1200
3
0
4
0003 03040200
FFFF0200
1000
0200
0200
0
0
0
0
![Page 35: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/35.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Summary
I A little more hardware ...
I ... to allow immediates as last argument
I Immediates part of instruction
![Page 36: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/36.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
(Trick) questions
I How many bits do we need for each instruction?
I Can we increment a register? How?
I Can we execute ADDII $1, 0x1, 0x2? How?
I Can we multiply 2 registers? How?
I Can we execute an if statement? How?
![Page 37: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/37.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Conditional execution and jumps
GoalImplement if/else, switch, for, while, goto ...
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ
Example programLOADI a, 8 # a = 8;
LOADI b, 4 # b = 4;
LOADI r, 0 # r = 0;
loop:
BZ b, end # while (b != 0) {
ADD r, r, a # r += a;
SUBI b, b, 1 # --b;
BRA loop # }
end:
![Page 38: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/38.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Conditional execution and jumps
GoalImplement if/else, switch, for, while, goto ...
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ
Example programLOADI a, 8 # a = 8;
LOADI b, 4 # b = 4;
LOADI r, 0 # r = 0;
loop:
BZ b, end # while (b != 0) {
ADD r, r, a # r += a;
SUBI b, b, 1 # --b;
BRA loop # }
end:
![Page 39: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/39.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Conditional execution and jumps
GoalImplement if/else, switch, for, while, goto ...
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ
Example programLOADI a, 8 # a = 8;
LOADI b, 4 # b = 4;
LOADI r, 0 # r = 0;
loop:
BZ b, end # while (b != 0) {
ADD r, r, a # r += a;
SUBI b, b, 1 # --b;
BRA loop # }
end:
![Page 40: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/40.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Implementing jumps
Do we jump?Where do we jump to?Do we write to register?
![Page 41: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/41.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Arithmetic logic unit (ALU)
Purpose: performs computation and tests
S0 S1 output
0 0 A + B0 1 A− B1 0 A & B1 1 B
I 2 bits to select operation
I Zero bit is set when output is zero
![Page 42: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/42.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Summary
I A bunch more hardwareI Hardware executes a branch when
I Instruction is a branch instructionI Test succeeds (ALU outputs zero)
I Target of jump is encoded in instruction
![Page 43: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/43.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
(Trick) questions
I How many bits do we need for each instruction?
I How can we test for (with A and B registers)
A = 0 A = 1 A = B A 6= B A < B
I Can we multiply 2 registers? How?
I Can we execute an if statement? How?
I Can we execute an if/else statement? How?
I Is Branch the negation of RegWrite?
![Page 44: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/44.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
More/main memory
GoalAdd memory. We add 216 = 65536 variables
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ,LW, SW
Example programLW $1, 10, $6 # Load mem[Reg6 + 10] into Reg1
SW $2, 10, $6 # Store $2 into mem[Reg6 + 10]
![Page 45: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/45.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
More/main memory
GoalAdd memory. We add 216 = 65536 variables
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ,LW, SW
Example programLW $1, 10, $6 # Load mem[Reg6 + 10] into Reg1
SW $2, 10, $6 # Store $2 into mem[Reg6 + 10]
![Page 46: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/46.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
More/main memory
GoalAdd memory. We add 216 = 65536 variables
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ,LW, SW
Example programLW $1, 10, $6 # Load mem[Reg6 + 10] into Reg1
SW $2, 10, $6 # Store $2 into mem[Reg6 + 10]
![Page 47: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/47.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Implementing main memory
Do we read from/write to memory?Write what where? Value read?
![Page 48: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/48.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Summary
I We simply “bolted on” some memory
I Both in hardware
I And in software
![Page 49: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/49.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
(Trick) questions
I How many bits do we need for each instruction?
I Why not simply increase the number of registers?
I Can we perform a computation (say A + B) and writethe result to memory using a single instruction?
I Can we execute an if statement? How?
I What if we want more than 216 = 65536 variables?
I Can a program modify itself? (polymorphic code)
![Page 50: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/50.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Procedure calls
GoalRe-use blocks of code
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ,LW, SW, CALL, RETURN
Example programLOADI $arg1, 1
LOADI $arg2, 2
LOADI $arg3, 3
CALL $ra, Add3
#--------------- Add3 procedure -----------------
Add3:
ADD $val1, $arg1, $arg2
ADD $val1, $val1, $arg3
RETURN $ra
![Page 51: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/51.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Procedure calls
GoalRe-use blocks of code
Instruction setADD(I), SUB(I), AND(I), COPY, LOADI, BRA, BZ, BEQ,LW, SW, CALL, RETURN
Example programLOADI $arg1, 1
LOADI $arg2, 2
LOADI $arg3, 3
CALL $ra, Add3
#--------------- Add3 procedure -----------------
Add3:
ADD $val1, $arg1, $arg2
ADD $val1, $val1, $arg3
RETURN $ra
![Page 52: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/52.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Implementing procedure calls
Do we CALL/RETURN?Store PC+1 in register (for CALL)Load PC from register (for RETURN)
![Page 53: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/53.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Summary
I We allow store and load of PC
I Increment to return to instruction after call
I Contract (calling convention) between caller and callee
![Page 54: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/54.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
(Trick) questions
I How can we compute the PC at a given instruction?
I Can we implement a dispatch table? (function pointer)
I Can a procedure call another procedure?
I What about recursion?
![Page 55: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/55.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Conclusion
I We built a general purpose processor
I In incremental steps
![Page 56: Computer architecture - The simplest processor - Cwi](https://reader031.vdocument.in/reader031/viewer/2022021007/620393e7da24ad121e4b08f4/html5/thumbnails/56.jpg)
Simple Processor
Koolen
Introduction
Calculator
Immediates
Jumps
Data memory
Procedure calls
Conclusion
Advanced tricks
Advanced tricks
I Asynchronous designNo clock
I CachingFast small memory on top of slow big memory
I Register stacksAccelerated procedure calls
I Floating point arithmetic, multimedia, encryptionUpgrade the ALU
I Very large instruction word (VLIW)Multiple independent ALUs
I PipeliningExecute multiple (sub-)instructions simultaneously
I Multi-core/processorMultiple processors attached to a single main memory