www.nand2tetris.org
Babbage’s Analytical Engine (1835)
!
"
#
Some early computers and computer scientists
Blaise Pascal
Von Neumann machine
(circa 1940)
Arithmetic Logic
Unit (ALU)
CPU
Registers
Control
Memory
(data
+
instructions)
Input
device
Output
device
Arithmetic Logic
Unit (ALU)
CPU
Registers
Control
Memory
(data
+
instructions)
Input
device
Output
device
Processing logic: fetch-execute cycle
(
) *
+
ALU
out = f (register values)
ALU
,
-The Hack chip-set and hardware platform
Nand
Not
And
Or
Xor
Mux
Dmux
Not16
And16
Or16
Mux16
Or8Way
Mux4Way16
Mux8Way16
DMux4Way
DMux8Way
HalfAdder
FullAdder
Add16
Inc16
ALU
DFF
Bit
Register
RAM8
RAM64
RAM512
RAM4K
RAM16K
PC
Memory
CPU
Computer
done
done
done
The Hack computer
.
+ )
*
/
!01.#
.
!0 .#*
2
3
2
4
!
#
2
5
!
#
67
!
#-$8
9
:
;
4
* <$=
=<8
,
)
5
*
Lecture / construction plan
/
.
*
3
4
5
Instruction memory
out
15
16
address
ROM32K
>
*
;
ROM
+ )
;
ROM
$8
*
out = ROM32K[address]
-Data memory
"
!
#
?
*
;
RAM[
)
]
*
address
),
out
;
RAM[
)
]
@(*
address
),
in
(,
load
$,
)
+
!14#
?
*
;
RAM[
)
]
*
14
out = peek(
)
)
;
RAM[
)
]
@(*
14
poke(
)
,
(
)
peek
poke
14
.
peek
poke
,
A
Lecture / construction plan
/
.
*
3
4
5
Screen
;
4
0 .
*
*
out = Screen[address]
*
if load then Screen[address] = in
4
*
=<8
<$=
)
load
out
in
16
15
16
address
Screen
Physical
Screen
;
Screen.hdl
D
Screen memory map
+
(row,col)
(
)
*
"
!
#* 4
col%16
Screen[row*32+col/16]
1
0
!
col/16
#
+
* 7
14
drawPixel(row,col)
0 1
255
. . .
. . .
0 1 2 3 4 5 6 7 511
0011000000000000 0000000000000000
0000000000000000 0
0001110000000000 0000000000000000
0000000000000000 32
0100100000000000 0000000000000000
0000000000000000 8129
8130
8160
. . .
row 255
. . .
refresh several times each second
Screen
/
+ )
,
'5
-Keyboard
5
*
$8
/
*
!$8
#
) ,
E
)
1
*
+
)
*
"
!
#*
Keyboard
+
*
14
keyPressed()
4
)
*
;
)
Keyboard.hdl
-,
)
)
)
-;
)
Lecture / construction plan
/
.
*
3
4
5
Memory:
conceptual / programmer’s view
7
*
;
! - -
,
,
#,
$85
;
!
#,
( '5
Data
Screen
memory
map
Keyboard map
Memory
Memory:
physical implementation
*
E
$8,F'F
RAM16K
$8,F'G
=G,<%<
Screen
=G,<%8
keyboard
load
out
in
16
15
16
RAM16K
(16K mem. chip)
address
0
16383
Screen
(8K mem. chip)
16384
24575
24576
Keyboard
(one register)
Memory
Keyboard
Screen
;
Memory
)
RAM16K
,
Screen
,
Keyboard
,
-;
)
A
,
-Lecture / construction plan
/
.
*
3
4
5
A pledge to patience ...
H
/
,
II
- /
, /
- ;
,
-
,
H B
D
(
- 1
)
-
CPU
instruction
inM
16
1
15
15
16
outM
16
writeM
addressM
pc
reset
1
C
P
U
to data
memory
to instruction
memory
from
data memory
from
instruction
memory
CPU
instruction
inM
16
1
15
15
16
outM
16
writeM
addressM
pc
reset
1
C
P
U
to data
memory
to instruction
memory
from
data memory
from
instruction
memory
The
C
-instruction revisited
jum p
dest
com p
1
1
1
a c 1 c 2 c 3 c 4 c 5 c 6 d 1 d 2 d 3 j 1 j 2 j 3binary:
(
*
reset
inM
addressM
pc
outM
A/M
instruction
decode
C ALU output
writeM
C C