The following pseudo-code describes the actions of the 2-pass assembler. It
most closely describes an Intel 80x86 format.
Pass 1
Initialize location counter (lc), symbol table and misc.
read source code line
while not END statement
do
if line is not comment then
if line declares a symbol then
note symbolic labels - enter symbol and location counter or value
(if EQU statement) into symbol table
endif
if line contains a literal then
endif
get mnemonic opcode from line
if opcode is pseudo-instruction then
act on pseudo-instruction
else
determine instruction type and length
reconize scope, near memory, far memory, register
note relocatable and external memory references
save in a table.
endif
write source code line and determined information about opcode on
line to a scratch file.
endif ( not comment lines)
read next line in source code
endwhile
Note entry point to program indicated by END
sort literal table and remove duplicates.
Pass 2
Initialize lc to 0 and perform other initializations.
read line temp file created by pass 1
while not end of file
do
evaluate type and replace mnemonic with ISA binary code
determine operands
if operand reference to literals then
find storage location of literals
else if relocatable reference then
calculate relative address-
determine location relative to beginning of module or command
else if external reference then
create empty segment:offset operand - zero out appropriate number
of bytes
else
generate other operands - such as register/register format or
immediate value (not supported by all cpus)
endif
write binary translation to object file.
write listing to listing file
endwhile
perform cleanup including writing relocation and external reference info
to object module for linking.