Title: Assembler Tutorial
1Assembler Tutorial
- This program is part of the software suite
- that accompanies the book
- The Digital Core, by Noam Nisan and Shimon
Schocken - 2003, www.idc.ac.il/csd, forthcoming by MIT Press
- The software suite was developed by students at
the - Efi Arazi School of Computer Science at IDC
- Chief Software Architect Yaron Ukrainitz
2The books software suite
- Translators
- Assembler translates programs written in the
Hack assembly language to executable code written
in the Hack machine language - JcVM (modeled after Javas JVM) translates
programs written in the stack-based Virtual
Machine (VM) language to assembly programs - Jack Compiler translates programs written in the
Java-like Jack language to VM programs that can
run on the Virtual Machine.
3The books software suite
4Assembler Tutorial
- Purpose learn how to use the supplied Assembler,
designed to translate programs from Hack assembly
to Hack machine code - Required knowledge Chapter 5 of the book
- Contents
- I. Assembly program example
- II. Command-level Assembler
- III. Interactive Assembler
5Assembler Tutorial
Part I Before we start talking about the
Assembler, lets take a look at a typical
assembly program
6Example
sum.asm
/ sum12 100 / _at_i // i1 M1 _at_sum
// sum0 M0 (loop) _at_i // if i-1000 goto
end DM _at_100 DD-A _at_end Djgt _at_i //
sumi DM _at_sum MDM _at_I //
i MM1 _at_loop // goto loop 0jmp (end)
7Example
sum.asm
/ sum12 100 / _at_i // i1 M1 _at_sum
// sum0 M0 (loop) _at_i // if i-1000 goto
end DM _at_100 DD-A _at_end Djgt _at_i //
sumi DM _at_sum MDM _at_I //
i MM1 _at_loop // goto loop 0jmp (end)
- The assembly program
- Stored in a text file named Prog.asm
- Written and edited in a text editor
- The assembly process
- Translates Prog.asm into Prog.bin
- Comments and white space are ignored
- Variables (e.g. i and sum) are allocated to
memory - Labels (e.g. loop and end) are psuedo commands
that generate no code - Each assembly command is translated into a 16-bit
instruction written in the Hack machine language.
8Assembler Tutorial
- Purpose learn how to use the supplied Assembler,
designed to translate programs from Hack assembly
to Hack machine code - Required knowledge Chapter 5 of the book
- Contents
- I. Assembly program example
- II. Command-level Assembler
- III. Interactive Assembler
9Assembler Tutorial
Part II Learn how to use the Assembler from the
operating systems shell level, batch style. (the
Assembler that you have to write should have the
same GUI and behavior)
10The command-level assembler
The OS type command can be used to inspect the
assembly source (.asm file)
(in your computer the path will probably be
different)
11Inspecting the source file
Source code is shown
12Invoking the Assembler
Invoke the Assembler program
Name of the source assembly file (full path).
This file name is an argument of the Assembler
program.
13Invoking the Assembler
The OS type command can be used to inspect the
translated code(.bin file)
14Inspecting the translated code
Binary code is shown
Two ways to test the binary code 1. Invoke the
Hardware Simulator, load the Computer chip, then
load the code (.bin file) into the internal ROM
chip 2. Load and run the code in the CPU
Emulator (much quicker).
15Assembler Tutorial
- Purpose learn how to use the supplied Assembler,
designed to translate programs from Hack assembly
to Hack machine code - Required knowledge Chapter 5 of the book
- Contents
- I. Assembly program example
- II. Command-level Assembler
- III. Interactive Assembler
16Hardware Simulation Tutorial
Part III Learn how to use the interactive
assembler
17Loading an assembly program
1. To load an assembly program, click here.
2. Navigate to a directory and select an .asm
file.
18Loading an assembly program
- Read-only view of the assembly source code
- To edit it, use an external text editor.
19Translating a program
Immediate translation(no animation)
Re-start the translation
Stop the translation
Translate the entire program
Translate line-by-line
20Inspecting the translation
21Saving the translated code
Saves the translated binary code in a .bin file
- If an assembly command contains a syntax error,
the translation stops with an error message - The save file operation is enabled only if the
translation was error-free.
22Comparing the translated code to a compare-file
1. Load a comparison file
2. Select a comparison (.bin) file
23Comparing the translated code to a compare-file
2, Translate the program (any translation mode
can be used, as usual)
1. Comparison file is shown
24Comparing the translated code to a compare-file
The translation of the highlighted line does not
match the corresponding line in the compare file.
25- Mistakes are the portals of discovery
- James Joyce (1882-1941)