Insert Lecture Name
22 Pages
English

Insert Lecture Name

-

Downloading requires you to have access to the YouScribe library
Learn all about the services we offer

Description

Assembler Tutorial
This program is part of the software suite
that accompanies the book
The Elements of Computing Systems
by Noam
Nisan and Shimon Schocken
MIT Press
www.idc.ac.il/tecs
This software was devel
oped by students at the
Efi
Arazi
School of Computer
Science at IDC
Chief Software Architect: Yaron
U
krainitz
Assembl
e
r Tutorial, w
ww.idc.ac.i
l
/tecs
Tutorial In
d
e
x
Slide 1/22 Background
The E
l
ements of
C
omp
ut
i
ng Sy
s
t
ems
evolves around
the
construction of a com
p
le
te
com
p
uter syste
m
,

do
ne
in the
framework o
f

a 1-
or 2-semester course.
In the
first part o
f
the
boo
k/course, we build the

ha
rdwa
re platform of a simple yet powerful
computer, called Hack. In
the
second part, we build
the computer’s software hiera
r
chy, consisting of an
asse
mbl
e
r, a virtual machine, a sim
p
le
Java-lik
e
language called Jack, a compiler for it, and a mini
operating system, written in Jack.
The book/course is completely self-contained,
requiring only p
r
ogrammi
ng as a pre-requisite.
The book’s web site in
cludes some 200 test
progra
ms, test scripts, and all the software
to
ols ne
cessary for doing all th
e projects.
Assembl
e
r Tutorial, w
ww.idc.ac.i
l
/tecs
Tutorial In
d
e
x
Slide 2/22







The book’s software suite
(All the suppli
e
d tools are dual
-pl
atform:
Xxx.bat
st
arts
Xxx
in Windows, and
Xxx.sh
starts it in Unix)
Simulator
s
(
HardwareSimulator
,
CPUEmulator
,
VMEmulator
):
This tutorial is ...

Subjects

Informations

Published by
Reads 55
Language English
Assembler Tutorial
This program is part of the software suite that accompanies the book
The Elements of Computing Systems by Noam Nisan and Shimon Schocken
MIT Press
www.idc.ac.il/tecs
This software was developed by students at the Efi Arazi School of Computer Science at IDC
Chief Software Architect: Yaron Ukrainitz
orial, wbler Tut2/A2ssmeSiled2 xdeInl iaorutsTcet/li.ca.cdi.ww
The Elements of Computing Systemsevolves around the construction of a complete computer system, done in the framework of a 1- or 2-semester course. In the first part of the book/course, we build the hardware platform of a simple yet powerful computer, called Hack. In the second part, we build the computers software hierarchy, consisting of an assembler, a virtual machine, a simple Java-like language called Jack, a compiler for it, and a mini operating system, written in Jack. The book/course is completely self-contained, requiring only programming as a pre-requisite. The books web site includes some 200 test programs, test scripts, and all the software tools necessary for doing all the projects.
Background
The book’s software suite (All the supplied tools are dual-platform: Xxx.bat starts Xxx in Windows, and Xxx.sh starts it in Unix) Simulators ( HardwareSimulator , CPUEmulator , VMEmulator ): This tutorial is ƒ Used to build hardware platforms and about the o assembler execute pr grams; ƒ Supplied by us. Translators ( Assembler , JackCompiler ): ƒ Used to translate from high-level to low-level; students, using the book’s The machine code generated by solutions supplied by us. the assembler can be tested either in the hardware simulator or in the CPU emulator. d translators software; ƒ builtIn : executable versions of all the logic gates and chips mentioned in the book; ƒ OS : executable version of the Jack OS; ƒ TextComparer : a text comparison utility. Assembler Tutorial, www.idc.ac.il/tecs Tutorial Index Slide 3/22
Assembler Tutorial
I. Assembly program example
II. Command-level Assembler
III. Interactive Assembler
Relevant reading: Chapter 4: Machine and Assembly Language
Assembler Tutorial, www.idc.ac.il/tecs
Tutorial Index
Slide 4/22
Assembler Tutorial
Assembler Tutorial, www.idc.ac.il/tecs
Part I:
Assembly
Programming
at a Glance
Tutorial Index
Slide 5/22
lembseAs226/e idlSxednirotI lal/tecsTuidc.ac.ila ,ww.w ruTotir
Sum.asm // Computes sum=1+...+100. @i // i=1 M=1 @sum // sum=0 M=0 (LOOP) @i // if (i-100)=0 goto END D=M @100 D=D-A @END D;JGT @i // sum+=i D=M @sum M=D+M @i // i++ M=M+1 @LOOP // goto LOOP 0;JMP (END) // infinite loop @END 0;JMP
Example
Sum.hack 0000000000010000 1110111111001000 0000000000010001 1110101010001000 0000000000010000 1111110000010000 0000000001100100 1110010011010000 0000000000010010 1110001100000001 0000000000010000 1111110000010000 0000000000010001 1111000010001000 0000000000010000 1111110111001000 0000000000000100 1110101010000111
Assembler
.wdi.ccai./letscTutorial Index
Sum.asm // Computes sum=1+...+100. @i // i=1 M=1 @sum // sum=0 M=0 (LOOP) @i // if (i-100)=0 goto END D=M @100 D=D-A @END D;JGT @i // sum+=i D=M @sum M=D+M @i // i++ M=M+1 @LOOP // goto LOOP 0;JMP (END) // infinite loop @END 0;JMP
The assembly process: ƒ Translates Prog.asm into Prog.hack ƒ Eliminates comments and white space ƒ Allocates variables (e.g. i and sum ) to memory ƒ Translates each assembly command into a single 16-bit instruction written in the Hack machine language ƒ Treats label declarations like (LOOP) and (END) as pseudo commands that generate no code.
The assembly program: ƒ Stored in a text file named Prog.asm ƒ Written and edited in a text editor
Example
lSdi e/722sAesbmler Tutorial, ww
Assembler Tutorial
Part II:
Learn how to invoke the supplied assembler from the OS shell level.
(the assembler that you have to write in project 6 should have the same GUI and behavior)
Assembler Tutorial, www.idc.ac.il/tecs
Tutorial Index
Slide 8/22
xnIedecsTil/tial utorwww ,lai.ca.cdi.blemss2Aorut TerSiled9 2/
Display the assembly source code (contents of the .asm text file)
We illustrate how to use the assembler in the Windows command level (DOS); The Unix way is similar.
The command-level assembler
Inspecting the source file
Assembler Tutorial, www.idc.ac.il/tecs
Tutorial Index
Source code is shown
Slide 10/22
Invoking the Assembler
Invoke the assembler program
Assembler Tutorial, www.idc.ac.il/tecs
Name of the file to be translated (argument of the assembler program).
Tutorial Index
Slide 11/22