程序代写代做代考 Java assembly compiler assembler computer architecture C CL19 – Basic Assembler Concepts

CL19 – Basic Assembler Concepts
1

The Big Picture
human thought
Our focus in thesemodules is on understandiy how assemblers work and how to create Assemblersoftware
abstraction
computer architecture
digital design
hardware platform
write a program
software hierarchy
p4
abstraction
CPU, RAM, chipset
comb. and seq. Logic
p2
p5
abstraction
elementary logic gates
combinational logic
p1
abstraction
high-level language
compiler
VM translator
OS
abstraction
VM code
abstraction
machine language
assembler
p6
Credit: www.nand2tetris.org
2
p3

Program Translation Process
PONG
High Level Language code
if ((x+width)>511) {
let x=511-width;
}

push x
push width add
push 511 gt if-goto L1 goto L2
L1:
push 511
push width
sub
pop x codeL2:

onvert Assembb
I
00
Athe
movement to thewall
VM translator
Assembly program
// push 511 @511
D=A
@SP
A=M
Bat
bat checkif theRIGHT
beyond the
converts lineforline codeinto
goes align so the
ofassembly corresponding machine
andif edgeofwall Right outtathe
// D=511
// *SP=D M=M+1 // SP++
code
bat
Assembler
Executable
0 wetakoefByte
@SP @SP
0000000000000000 1110110010001000
Machine Language
line
c
to
to
3
Virtual machine program
Ball Boat’Icode just
like Java
Courtesy: nand2tetris.org
M=D
T

Assembly process
Assembly Language
Machine Language
0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000000000000 1111010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 …
@i
M=1 // i = 1 @sum
M=0 //sum=0
(LOOP)
@i // if i>RAM[0] D=M // GOTP WRITE @R0
D=D-M
@WRITE
D;JGT
… // Etc.
assembler run
Credit: www.nand2tetris.org 4

Why care about assemblers?
• Assemblers are the first rung up the software hierarchy ladder
• An assembler is a translator of a simple language
• Writing an assembler = low-impact practice for writing compilers.
5

HACK Machine Instructions
A Instruction
non negative 7
et I n is maintainedas a nonnegcalm
Hagonminenjheathat Bitformat o gniude
syntax
D ATD dest op
P 9 op jump
in
211noO l 1514131211 to 543
2I
gumpbil DJLE
fyl.si
C Instruction
bitform In T bi Tets
bib
I l l act c2C3c4C5C6 dl d2d3
a
opcode
destsop jump
op bits
optional but not both
6
Instruction

COMP BEST
JUMP
O
7

Refresh: HACK Computer Simplified
CPU
ALU
D register
A register
PC
instruction memory
data memory
instruction
data out
address data in
of next instruction
8

HACK Registers
• D Register Ffa yD
• A Register
Register
i dataregister
FIM 11D MUD
AMEDmt
11MLA
MEAT 11
Rom Inst
Tea
Hao If D
ROMCA
0
9

Simple ADD Program RAM[2] = RAM[1] + RAM[0]
If this program addscontentofmemory locetons O andA
A
x
11 and stores the resultin men 11ie MEI MColtMCD
locetron 2
ID
2 MDHM
iii
m
DtM 11DtMa
me
2
D
x
10

HACK Assembly – Manual Assembly
o
O
Assembler
b
OP il r A Cl c2C3 Cdcs Cs did2d3s1j2j3 a
C lust A instr
1 number I1i
op
tl ll
O O O O O O O O co o O 0 O O 0 Oi t I l f I l Q O O O I 0 O 00 I 0.00OOOOO 00 oOOOI1 IsANlI O O O I 010 O O004
a
11

What’s next?
van it
them in assembler EEI
gpey.qygngqgm.gg
software that
you
dad w
symbols
how to deal
w
How to deal How to write
acaegmompbshe.tk
12