0% found this document useful (0 votes)
16K views

One Pass Assembler

One-pass assemblers avoid the need for a second pass over the source program by allowing forward references, which can cause problems. Data structures like an opcode table and symbol table are used to translate assembly code to machine code in a single pass. The assembler assigns addresses in the first pass and processes forward references when definitions are encountered. Load-and-go assemblers generate object code directly in memory for immediate execution without writing an object file.

Uploaded by

Tanvi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16K views

One Pass Assembler

One-pass assemblers avoid the need for a second pass over the source program by allowing forward references, which can cause problems. Data structures like an opcode table and symbol table are used to translate assembly code to machine code in a single pass. The assembler assigns addresses in the first pass and processes forward references when definitions are encountered. Load-and-go assemblers generate object code directly in memory for immediate execution without writing an object file.

Uploaded by

Tanvi Sharma
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

Translate assembly language programs to object programs or machine

code is called an Assembler.


One-pass assemblers are used when
it is necessary or desirable to avoid a second pass over the source program
the external storage for the intermediate file between two passes is slow or is
inconvenient to use
Main problem: forward references to both data and instructions
One simple way to eliminate this problem: require that all areas be defined befo
re they are referenced.
It is possible, although inconvenient, to do so for data items.
Forward jump to instruction items cannot be easily eliminated.
Data structures for assembler:
Op code table
Looked up for the translation of mnemonic code
key: mnemonic code
result: bits
Hashing is usually used
once prepared, the table is not changed
efficient lookup is desired
since mnemonic code is predefined, the hashing function can be tuned a priori
The table may have the instruction format and length
to decide where to put op code bits, operands bits, offset bits
for variable instruction size
used to calculate the address
Symbol table
Stored and looked up to assign address to labels
efficient insertion and retrieval is needed
deletion does not occur
Difficulties in hashing
non random keys
Problem
the size varies widely
pass 1: loop until the end of the program
1. Read in a line of assembly code
2. Assign an address to this line
increment N (word addressing or byte addressing)
3. Save address values assigned to labels
in symbol tables
4. Process assembler directives
constant declaration
space reservation
Algorithm for Pass 1 assembler:
begin
if starting address is given
LOCCTR = starting address;
else

LOCCTR = 0;
while OPCODE != END do
;; or EOF
begin
read a line from the code
if there is a label
if this label is in SYMTAB, then error
else insert (label, LOCCTR) into SYMTAB
search OPTAB for the op code
if found
LOCCTR += N
;; N is the length of
this instruction (4 for MIPS)
else if this is an assembly directive
update LOCCTR as directed
else error
write line to intermediate file
end
program size = LOCCTR - starting address;
end
Load-and-go assembler
Load-and-go assembler generates their object code in memory for immediate execut
ion.
No object program is written out, no loader is needed.
It is useful in a system oriented toward program development and testing such th
at the efficiency of the assembly process is an important consideration
Forward Reference:
Load-and-go assembler
Omits the operand address if the symbol has not yet been defined
Enters this undefined symbol into SYMTAB and indicates that it is undefined
Adds the address of this operand address to a list of forward references associa
ted with the SYMTAB entry
Scans the reference list and inserts the address when the definition for the sym
bol is encountered.
Reports the error if there are still SYMTAB entries indicated undefined symbols
at the end of the program
Search SYMTAB for the symbol named in the END statement and jumps to this locati
on to begin execution if there is no error

You might also like