1-Pass Assembler Algorithm
1-Pass Assembler Algorithm
Begin
Read first input line
If OPCODE = START then
Begin
Save #[OPERAND] as starting address
Initialize LOCCTR to starting address
Write line to intermediate file
Read next input line
End { if START }
Else
Initialize LOCCTR=0
While OPCODE != END do
Begin
If this is not a comment line then
Begin
If there is a symbol in the LABEL Field then
Begin
Search SYMTAB for LABEL
If found then
Set error flag (duplicate symbol)
Else
Insert (LABEL,LOCCTR) into SYMTAB
End {if Symbol }
Search OPTAB for OPCODE
If found then
Add 3 to LOCCTR
Else if OPCODE = WORD then
Add 3 to LOCCTR
Else if OPCODE = RESW then
Add 3 * #[OPERAND] to LOCCTR
Else if OPCODE = RESB then
Add #[OPERAND] to LOCCTR
Else if OPCODE = BYTE then
Begin
Find length of constant in bytes
Add length to LOCCTR
End
Else
Set error flag (invalid operation code )
End { if not comment }
Write line to intermediate file
Read next input line
End { While Loop }
Write last line to intermediate file
Save LOCCTR as program length
End { Pass 1 }