Beruflich Dokumente
Kultur Dokumente
Computer
Architecture
From Nand to Tetris
www.nand2tetris.org
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 1
Babbage’s Analytical
Engine (1835)
“We may say most aptly that the Analytical Engine weaves
algebraic patterns just as the Jacquard-loom weaves
flowers and leaves”
(Ada Lovelace)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 2
Some early computers and
computer scientists
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 3
Mauchly & Eckert
• ENIAC (Electronic Numerical Integrator and Calculator
– 1946 = Developed for the military (firing tables WWII)
– Not “published” until
well after the war
• 17,468 vacuum tubes
• 70,000 resistors
• 10,000 capacitors
• 1,500 relays
• 6,000 manual switches
• 1,800 sq. feet of floor space, weighed 30 tons!
• UNIVAC (UNIVersal Automatic Computer)
– 1951 = Developed for the census bureau (baby boomers)
– 1952 = successfully predicted the outcome of the
Eisenhower-Stevenson election
– Used magnetic tape, much faster than IBMs punch cards
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 4
Von Neumann machine (circa 1940)
CPU
Input
device
Memory Arithmetic Logic
Unit (ALU)
(data
+ Registers
instructions)
Output
Control device
Stored
program
concept!
Keyboard
Andy Grove (and others) ...
John Von Neumann (and others) ... made it possible made it small and fast.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 5
Processing logic:
fetch-execute cycle
CPU
Input
device
Memory Arithmetic Logic
Unit (ALU)
(data
+ Registers
instructions)
Output
Control device
Keyboard
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 6
The Hack chip-set and
hardware platform
Elementary logic gates Combinational chips Sequential chips Computer Architecture
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 8
Lecture / construction plan
• Instruction memory
• Memory:
q Data memory
q Screen
q Keyboard
• CPU
• Computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 9
Instruction memory
address out
ROM32K
15 16
Use built-in
ROM32K
chip for
Function: HW
• The ROM is pre-loaded with a program written in the
Hack machine language (manually by us in simulator)
• The ROM chip always emits a 16-bit number:
out = ROM32K[address]
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 10
Data memory
load
set load to 1, 15
14
n Memory:
P q Data memory
q Screen
q Keyboard
n CPU
n Computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 12
Screen
The Screen chip has a basic RAM chip functionality:
q read logic: out = Screen[address]
Simulated screen:
q write logic: if load then Screen[address] = in
Side effect:
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 13
Screen memory map
0 0011000000000000
0 1 2 3 4 5 6 7 ... 511
1 0000000000000000
In the Hack platform, 0 ...
. row 0 1 ...
the screen is .
.
implemented as an 8K 31 0000000000000000
. .
32 0001110000000000
16-bit RAM chip. 33 0000000000000000 . .
. .
. row 1
.
.
63 0000000000000000
255 ...
Screen
8160
8129 0100100000000000
8161
8130 0000000000000000
. row
. 255
. refresh several times
8191 each second
8160 0000000000000000
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 14
Keyboard
out Simulated keyboard:
Keyboard
16
Keyboard
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 15
Lecture / construction plan
P n Instruction memory
n Memory:
P q Data memory
P q Screen
P q Keyboard
n CPU
n Computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 16
Memory: conceptual / programmer’s view
Memory
Data
Use built-in
Screen +
Screen
Keyboard
memory chips for HW
map
Screen
Keyboard map
Keyboard
Using the memory:
q To record or recall values (e.g. variables, objects, arrays), use the first 16K words
of the memory
q To write to the screen (or read the screen), use the next 8K words of the
memory
q To read which key is currently pressed, use the next word of the memory.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 17
Memory (Implementation)
• The Memory chip is essentially a package
load
Memory that integrates the three chip-parts
RAM16K, Screen, and Keyboard into a single,
0 contiguous address space.
in
• This packaging effects the programmer’s
16
RAM16K
out
view of the memory, as well as the
(16K mem. chip)
necessary I/O side-effects.
16383 16
Keyboard
Access logic:
q Access to any address from 0 to 16,383 (inclusive) results in accessing the
RAM16K chip-part
q Access to any address from 16,384 to 24,575 (inclusive) results in
accessing the Screen chip-part
q Access to address 24,576 results in accessing the Keyboard chip-part
q Access to any other address is invalid.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 18
Memory Lab
Partner up!
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 19
Lecture / construction plan
P n Instruction memory
P n Memory:
P q Data memory
P q Screen
Keyboard
P q
n CPU
n Computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 20
A pledge to patience ...
“At times … the fragments that I lay out for your inspection may seem not
to fit well together, as if they were stray pieces from separate puzzles. In
such cases, I would counsel patience. There are moments when a large
enough fragment can become a low wall, a second fragment another wall
to be raised at a right angle to the first. A few struts and beams later, and
we may made ourselves a rough foundation … But it can consume the
better part of a chapter to build such a foundation; and as we do so the
fragment that we are examining may seem unconnected to the larger
whole. Only when we step back can we see that we have been assembling
something that can stand in the wind.”
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 21
The A-instruction revisited
value (v = 0 or 1)
Binary: 0 v v v v v v v v v v v v v v v
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 22
The C-instruction revisited
dest = comp; jump comp dest jump
binary: 1 1 1 a c1 c2 c3 c4 c5 c6 d1 d2 d3 j1 j2 j3
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 23
CPU Lab
Partner up!
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 24
CPU from
data memory inM
16 outM
16
to data
writeM
CPU
from memory
instruction instruction 1
memory 16 addressM
15
pc to instruction
a Hack machine language reset 15
memory
instruction like M=D+M, 1
stated as a 16-bit value
CPU internal components (invisible in this chip diagram): ALU and 3 registers: A, D, PC
CPU fetch logic:
Recall that:
1. the instruction may include a jump directive (expressed as non-zero jump bits)
2. the ALU emits two control bits, indicating if the ALU output is zero or less than zero
If reset==0: the CPU uses this information (the jump bits and the ALU control bits) as:
If there should be a jump, the PC is set to the value of A; else, PC is set to PC+1
If reset==1: the PC is set to 0. (restarting the computer)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 25
CPU from
data memory inM
16 outM
16
to data
writeM
CPU
from memory
instruction instruction 1
memory 16 addressM
15
pc to instruction
a Hack machine language reset 15
memory
instruction like M=D+M, 1
stated as a 16-bit value
CPU internal components (invisible in this chip diagram): ALU and 3 registers: A, D, PC
CPU decode logic:
Recall that: the instruction is either an A- or C-instruction (how can we tell them apart?)
If A-instruction:
• Set A register to value
If C-Instruction:
• Break down into dest, comp, jump parts (how do you know what needs to be done?)
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 26
CPU
from
data memory inM
16 outM
16
to data
writeM
CPU
from memory
instruction instruction 1
memory 16 addressM
15
pc to instruction
a Hack machine language reset 15
memory
instruction like M=D+M, 1
stated as a 16-bit value
CPU internal components (invisible in this chip diagram): ALU and 3 registers: A, D, PC
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 27
CPU dest = comp; jump
binary: 1 1 1
comp dest jump
implementation a c1 c2 c3 c4 c5 c6 d1 d2 d3 j1 j2 j3
Chip diagram:
ALU output
q Includes most of the CPU’s
execution logic
q The CPU’s control logic is C
C C
instruction outM
ALU
C
q The “decode” A
Mux
A
bar does not instruction A/M
C
represent a
Mux
chip, but M
inM
rather indicates C writeM
that the A
instruction bits addressM
are decoded reset C
somehow.
Cycle: A
PC pc
q Decode
q Execute Decode logic: Execute logic: Resetting the
Fetch logic:
q Execute based If there’s a jump, computer:
q Fetch q Breakdown on decoded A- set PC to A
instruction or C- Set reset to 1,
instruction else set PC to PC+1
into parts then set PC to 0.
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 28
Lecture / construction plan
P n Instruction memory
P n Memory:
q Data memory
q Screen
q Keyboard
P n CPU
n Computer
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 29
Computer-on-a-chip interface
reset Screen
Computer
Keyboard
Keyboard
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 30
Computer-on-a-chip implementation
inM
writeM
Instruction outM Data
Memory instruction Memory
CPU
addressM
(ROM32K) (Memory)
pc
reset
CHIP Computer {
IN reset;
PARTS: Implementation:
// implementation missing
Simple, the chip-parts do all the hard work.
}
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 31
The spirit of things
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 32
“Ya, right,
Lecture plan but what about
the software?”
P n Instruction memory
P n Memory:
q Data memory
q Screen
q Keyboard
P n CPU
Computer
P n
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 33
Perspective: from here to a
“real” computer
• Caching
• Multi-core / parallelism
• Efficiency
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 34
Perspective: some issues we
haven’t discussed (among many)
• CISC / RISC (hardware / software trade-off)
• Silicon compilers
Elements of Computing Systems, Nisan & Schocken, MIT Press, www.nand2tetris.org , Chapter 2: Boolean Arithmetic slide 35