Chapter 6-assembler Flashcards
Programs in binary code have extension of?
Hack
Programs in assembly code have extension?
Asm
When a machine code is loaded into the computer’s memory to which segment of memory is it loaded and what will be the address of the n’th line?
Loaded into the instruction memory and will have address n
What does an assembly file composed from?
Instructions A and C and symbol
What is binded to the symbol?
The memory location into which the next command in the program will be stored
What is the A instruction?
@value is either non negative number or a symbol referring to such number.
The binary rep of A command is
0vvv vvvv vvvv vvvv where v is 0 or 1
What is c instruction?
Dest=comp;jump
Notice that comp or jump can be empty
The rep is
111a c1c2c3c4 c5c6d1d2 d3j1j2j3
Name the hack predefined symbols
SP LCL ARG THIS THAT R0-R15 SCREEN KBD
0. 1. 2. 3. 4. 0-15. 16384. 24576
How to define a symbol in assembly code?
(Xxx) it can be defined only once and can be used anywhere in the program also before the definition
What is a variable symbol in assembly code?
Any symbol Xxx which is not predefined and is not defined using (Xxx) is treated as a variable.
Variables are mapped to consecutive memory locations as they are first encounter, starting at ram address 16
What is the input and the output of the assembler?
The input is a prog.asm file and the output is
Prog.hack file
How to write the assembler?
- Parser which parse each line into command type, symbol, dest, comp, jump
- Code module which translate assembly into binary
Dest into 3 bits, comp into 7 bits and jump into 3 bits - The symbolTable module which is hash table of symbol to address RAM OR ROM
Assembly program can use labels before they are defined. What is the solution for this problem for assembly developers?
Two pass assembler.
First pass the assembler builds the symbol table and generates no code.
First init the table with all the predefined symbols.
First pass: go through line by line while keeping a running number of the ROM address, increment when C or A commands
When pseudo command (Xxx), add it to the symbol table,
Key: Xxx value: the ROM address that will store the next command.
In the second pass resolve the program variables symbols
When and how does the program variables are handled
In the second pass of the assembler.
Each time we have A command @xxx where xxx are not a number, lookup Xxx at the symbol table. If found, replace it with it’s numerical number,
If not found add to the table
Key Xxx, value: next available RAM address.
Now complete the command’s translation.