CS331 SYSTEM SOFTWARE LAB Department of CSE
PROGRAM No:13
PASS TWO OF A TWO PASS ASSEMBLER
Aim:
To write a program to implement pass two of a two pass assembler.
Note:
.An assembler is a translator, that translates an assembler program into a conventional
machine language program. Basically, the assembler goes through the program one line
at a time and generates machine code for that instruction. Then the assembler procedes to
the next instruction. In this way, the entire machine code program is created. For most
instructions this process works fine, for example for instructions that only reference
registers, the assembler can compute the machine code easily, since the assembler knows
where the registers are
Algorithm:
1 begin
2 read first input file {from intermediate file} 3 if OPCODE = 'START'
then 4 begin
a) write listing line
b) read next input line 5 end {if START}
6 write header record to object program 7 initialized first Text record
8 while OPCODE != 'END' do 9 begin
a) if this is not a comment line then
i) begin
ii) search OPTAB for OPCODE
iii) if found then
iv) begin
(1) if there is a symbol in OPERAND field then
(2) begin
(a) search SYMTAB for OPERAND
(b) if found then
(c) store symbol value as operand address
(d) else
(e) begin
(f) store 0 as operand address
(g) set error flag (undefined symbol)
(h) end
(3) end {if symbol}
(4) else
(5) store 0 as operand address
(6) assemble the object code instruction
i) end {if opcode found}
Page 1
CS331 SYSTEM SOFTWARE LAB Department of CSE
ii) else if OPCODE = 'BYTE' or 'WORD' then
iii) convert constant to object code
iv) if object code not fit into the current Text record then
v) begin
(7) write Text record to object program
(8) initialized new Text record
vi) end
vii) add object code to Text record
viii) end {if not comment}
b) write listing line read next input line
10 end {while not END}
11 write last Text record to object program 12 write End record to object program
13 write last listing line 14 end
Source code:
Page 2