Simple Two Pass Assembler
BEGIN
initialize Scnt, Locctr, ENDval, and Errorflag to 0
WHILE Sourceline[Scnt] is a comment
BEGIN
increment Scnt
END {while}
Breakup Sourceline[Scnt]
IF Opcode = 'START' THEN
BEGIN
convert Operand from hex and save in Locctr and ENDval
IF Label not NULL THEN
Insert (Label, Locctr) into Symtab
ENDIF
increment Scnt
Breakup Sourceline[Scnt]
END
ENDIF
WHILE Opcode <> 'END'
BEGIN
IF Sourceline[Scnt] is not a comment THEN
BEGIN
IF Label not NULL THEN
Xsearch Symtab for Label
IF not found
Insert (Label, Locctr) into Symtab
ELSE
set errors flag in Errors[Scnt]
ENDIF
ENDIF
Xsearch Opcodetab for Opcode
IF found THEN
DO CASE
1. Opcode is 'RESW' or 'RESB'
BEGIN
increment Locctr by Storageincr
IF error THEN
set errors flag in Errors[Scnt]
ENDIF
END {case 1 (RESW or RESB)}
2. Opcode is 'WORD' or 'BYTE' THEN
BEGIN
increment Locctr by Storageincr
IF error THEN
set errors flag in Errors[Scnt]
ENDIF
END {case 2 (WORD or BYTE)}
3. OTHERWISE
BEGIN
increment Locctr by Opcodeincr
IF error THEN
set errors flag in Errors[Scnt]
ENDIF {case 3 (default)}
END
ENDCASE
ELSE
/* directives such as BASE handled here or */
set errors flag in Errors[Scnt]
ENDIF
END {IF block}
ENDIF
increment Scnt
Breakup Sourceline[Scnt]
END {while}
IF Label not NULL THEN
Xsearch Symtab for Label
IF not found
Insert (Label, Locctr) into Symtab
ELSE
set errors flag in Errors[Scnt]
ENDIF
ENDIF
IF Operand not NULL
Xsearch Symtab for Operand
IF found
install in ENDval
ENDIF
ENDIF
END {of Pass 1}
0 comments:
Post a Comment