Two Pass Assembler Algorithm
Two Pass Assembler Algorithm
begin
read first input file {from intermediate file}
if OPCODE = 'START' then
begin
write listing line
read next input line
end {if START}
write header record to object program
initialized first Text record
while OPCODE != 'END' do
begin
if this is not a comment line then
begin
search OPTAB for OPCODE
if found then
begin
if there is a symbol in OPERAND field then
begin
search SYMTAB for OPERAND
if found then
store symbol value as operand address
else
begin
store 0 as operand address
set error flag (undefined symbol)
end
end {if symbol}
else
store 0 as operand address
assemble the object code instruction
end {if opcode found}
else if OPCODE = 'BYTE' or 'WORD' then
convert constant to object code
if object code not fit into the current Text record then
begin
write Text record to object program
initialized new Text record
end
add object code to Text record
end {if not comment}
write listing line
read next input line
end {while not END}
write last Text record to object program
write End record to object program
write last listing line
end