程序代写代做代考 compiler assembler computer architecture Java flex CSCE-312 Day 1 Introduction

CSCE-312 Day 1 Introduction

L17 – HACK Computer Architecture

Outline
Computer Architecture vs Computer Organization
Von Neumann vs Harvard architecture
Fetch-Execute Cycle
HACK Computer
2

The Big Picture

abstraction
VM translator

human
thought
VM code
compiler

abstraction

OS
write a program
abstraction

high-level
language
computer architecture
abstraction

CPU, RAM,
chipset
abstraction
elementary logic gates
abstraction

Nand
comb. and
seq. Logic

combinational logic

digital design

assembler
machine language
software hierarchy
hardware platform
p1
p2
p3
p4
p5
p6
Credit: www.nand2tetris.org
3

Architecture vs Organization
Architecture – Customer visible features for an artifact
Organization – Includes underlying details as well
4

Key Points
Computer Architecture exposes features of a computer that its primary customer aka the PROGRAMMER needs to know in order to use it.
The underlying details (programmer visible features or otherwise) constitute a computer’s organization. They are important to the DESIGNER of the computer, but not all are needed to be made visible to the programmer.
In this chapter we will realize the HACK ARCHITECTURE with its ORGANIZATION based on –
Instruction set definition (Chapter 4)
(Implemented) building block components (Chapters 1-3)
5

Stored Program Concept – von Neumann vs Harvard
Credit: www.nand2tetris.org
6

von Neumann architecture
Harvard architecture
Harvard Architecture (used by the Hack computer):
Two physically separate memory units: (Instruction memory and Data memory)
Advantage: Complication avoided (separate instruction and data memory)
Each can be addressed and manipulated separately, and simultaneously
Von Neumann, instead, uses complex multiplexed communication between the CPU and unified memory
Disadvantage:
Two memory chips instead of one in von Neumann architecture
The size of the two chips is fixed vs flexible in von Neumann architecture

6

Computer Operation at a high level
In stored program computer, computer operation at a high level amounts to the following two steps
Fetch the instruction from the instruction memory
Execute the instruction
7

Note – the above two steps, while true in modern computers, are deceptively complex in their realization

Hack Computer
Abstraction:
A computer capable of running programs written in the Hack machine language
Implementation:
Built from the Hack chip-set.

data
memory

CPU
instruc-
tion
memory
instruction
data out
data in
address

Hello, world

Credit: www.nand2tetris.org

This is remarkable – if we can write a compiler thattranslates Java to Hack, this computer can execute Java programs!
Abstraction: top down
Implementation: functionality
8

Hack CPU

data
memory

CPU
instruc-
tion
memory
instruction
data out
data in
address
Credit: www.nand2tetris.org

This is remarkable – if we can write a compiler thattranslates Java to Hack, this computer can execute Java programs!
Abstraction: top down
Implementation: functionality
9

Hack CPU

CPU abstraction:
Executes a Hack instruction and figures out which instruction to execute next
CPU Implementation:
To be discussed in the next module
Credit: www.nand2tetris.org

Hack Computer

data
memory

CPU
instruc-
tion
memory
instruction
data out
data in
address

Hello, world


Credit: www.nand2tetris.org

Memory

Memory

CPU
instruction
data out
data in
address

Hello, world

instruc-
tion
memory
Credit: www.nand2tetris.org

Memory
address
15
in
16
Memory: abstraction

Hello, world

RAM
(16K)
16,383
0

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384
load

Address 0 to 16383: data memory
Address 16384 to 24575: screen memory map
Address 24576: keyboard memory map
out
16
Credit: www.nand2tetris.org

Memory
address
15
in
16
Memory: implementation

Hello, world

RAM
(16K)
16,383
0

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384
load

Address 0 to 16383: data memory
Address 16384 to 24575: screen memory map
Address 24576: keyboard memory map
out
16
Credit: www.nand2tetris.org

Memory
address
15
in
16
out
16
RAM

RAM
(16K)
16,383
0

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384
load
built in project 3
The Hack RAM is realized by the RAM16K chip implemented in project 3.

Credit: www.nand2tetris.org

Screen

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384

RAM
(16K)
16,383
0
address
15
in
16

Hello, world

Keyboard
24,576
out
16
Memory
Credit: www.nand2tetris.org

Screen memory map
row 0

row 1

row 255

0000000000000000
63
0000000000000000
0000000000000000
8159
8160
0011000000000001
0000101000000000
0000000000000000
31
32
33

1111010100000000
0000000000000000
(16384) 0
1

1011010100000000
8191













Screen
refresh
To set pixel (row,col) on/off:
(1) word = RAM[16384 + 32*row + col/16]
(2) Set the (col % 16)th bit of word to 0 or 1
(3) RAM[ i ] = word




0
1
2
3
4
5
6
7

511

0

1

255















Display Unit (256 by 512, b/w)
Credit: www.nand2tetris.org

Memory
Screen

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384

RAM
(16K)
16,383
0
address
15
in
16

Hello, world

Keyboard
24,576
out
16

Hello, world

The Hack screen is realized by a built-in chip named Screen
Screen: a regular RAM + display output side-effect.
built-in chip
Credit: www.nand2tetris.org

Memory
Keyboard

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384

RAM
(16K)
16,383
0
address
15
in
16

out
16
Credit: www.nand2tetris.org

Keyboard memory map
0000000000000000
Keyboard

k
Scan-code of ‘k’ = 75
0000000001101011
0000000000110100
0000000001001011
The Keyboard chip emits the scan-code of the currently pressed key,
or 0 if no key is pressed.
Credit: www.nand2tetris.org

The Hack character set
key code
(space) 32
! 33
“ 34
# 35
$ 36
% 37
& 38
‘ 39
( 40
) 41
* 42
+ 43
, 44
– 45
. 46
/ 47

key code
0 48
1 49
… …
9 57

: 58
; 59
< 60 = 61 > 62
? 63
@ 64

key code
A 65
B 66
C …
… …
Z 90

[ 91
/ 92
] 93
^ 94
_ 95
` 96

key code
a 97
b 98
c 99
… …
z 122

key code
newline 128
backspace 129
left arrow 130
up arrow 131
right arrow 132
down arrow 133
home 134
end 135
Page up 136
Page down 137
insert 138
delete 139
esc 140
f1 141
… …
f12 152

{ 123
| 124
} 125
~ 126

Credit: www.nand2tetris.org

Memory
Keyboard

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384

RAM
(16K)
16,383
0
address
15
in
16

out
16

Realized by a built-in chip named Keyboard
Keyboard: A read-only 16-bit register + a keyboard input side-effect.
built-in chip
Credit: www.nand2tetris.org

Memory
Memory implementation

Keyboard
24,576

Screen
(8K memory map)
24,575
16,384

RAM
(16K)
16,383
0
address
15
in
16

out
16
Implementation outline:
Uses the three chip-parts RAM16K, Screen, and Keyboard (as just described)
Routes the address input to the correct address input of the relevant chip-part.

RAM
(16K)

Screen
(8K memory map)
load

Hello, world

Credit: www.nand2tetris.org

Hack Computer
reset
data
memory

CPU
instruc-
tion
memory
instruct.
data out
data in
address

Hello, world


reset
reset
Credit: www.nand2tetris.org

Instruction memory
Hack Computer
0000000000001101
1110101001010101
0000000000000001
1110101001101011
0000001100110101
1110010111011111

1111001001100111



Hack Program
Press “reset”
The program starts running.

Load a program into the Instruction Memory? How?

reset
data
memory

CPU
instruc-
tion
memory
instruct.
data out
data in
address
reset
To run a program on the Hack computer:
Load the program into the Instruction Memory
load
Credit: www.nand2tetris.org

Instruction memory
Hack Computer
0000000000001101
1110101001010101
0000000000000001
1110101001101011
0000001100110101
1110010111011111

1111001001100111



Hack Program

reset
data
memory

CPU
instruc-
tion
memory
instruct.
data out
data in
address
Loading a program into the Instruction Memory:
reset
load
Credit: www.nand2tetris.org

Instruction memory
Hack Computer
0000000000001101
1110101001010101
0000000000000001
1110101001101011
0000001100110101
1110010111011111

1111001001100111



Hack Program

reset
data
memory

CPU
instruc-
tion
memory
instruct.
data out
data in
address
Loading a program into the Instruction Memory:
Hardware implementation: plug-and-play ROM chips
(each comes pre-loaded with a program’s code)
Hardware simulation: programs are stored in text files;
The simulator’s software features a load-program service.
reset
load
Credit: www.nand2tetris.org

Instruction memory
The Hack Instruction Memory is realized by a built-in chip named ROM32K
ROM32K: a read-only, 16-bit, 32K RAM chip + program loading side-effect.

ROM32K
out
16
address
15
Built-in chip

(from: the
CPU’s pc output)
(to:
the CPU’s
instruction output)
Credit: www.nand2tetris.org

Hack Computer implementation
Credit: www.nand2tetris.org

Hack Computer implementation

Credit: www.nand2tetris.org

Hack Computer implementation

Credit: www.nand2tetris.org

Hack Computer implementation

Credit: www.nand2tetris.org

Hack Computer implementation

Credit: www.nand2tetris.org

Hack Computer implementation
Credit: www.nand2tetris.org

Hack Computer implementation
That’s it!

Hello, world

Credit: www.nand2tetris.org

Hack Computer implementation
“We ascribe beauty to that which is simple; which has no superfluous parts; which exactly answers its end; which stands related to all things; which is the mean of many extremes.”
— Ralph Waldo Emerson 

Hello, world

Credit: www.nand2tetris.org

Keyboard
Arithmetic Logic
Unit (ALU)
CPU
Registers
Control
Memory
(data
+
instructions)
Input
device
Output
device

/docProps/thumbnail.jpeg