Simple Two Pass Assembler
BEGIN
initialize Scnt, Locctr, Skip, and Errorflag to 0
write assembler report headings
WHILE Sourceline[Scnt] is a comment
BEGIN
append to assembler report
increment Scnt
END {while}
Breakup Sourceline[Scnt]
IF Opcode = 'START' THEN
BEGIN
convert Operand from hex and save in Locctr
append to assembler report
increment Scnt
Breakup Sourceline[Scnt]
END
ENDIF
format and place the load point on object code array
format and place ENDval on object code array, index ENDloc
WHILE Opcode <> 'END'
BEGIN
IF Sourceline[Scnt] is not a comment THEN
BEGIN
Xsearch Opcodetab for Opcode
IF found THEN
DO CASE
1. Opcode is 'RESW' or 'RESB'
BEGIN
increment Locctr by Storageincr
place '!' on object code array
replace the value at index ENDloc with loader address
format and place Locctr on object code array
format and place ENDval on object code array, index ENDloc
set Skip to 1
END
2. Opcode is 'WORD' or 'BYTE'
BEGIN
increment Locctr by Storageincr
Dostorage to get Objline
IF error THEN
set errors flag in Errors[Scnt]
ENDIF
END
3. OTHERWISE
BEGIN
increment Locctr by Opcodeincr
Doinstruct to get Objline
IF error THEN
set errors flag in Errors[Scnt]
ENDIF
END
ENDCASE
ELSE
/* directives such as BASE handled here or */
set errors flag in Errors[Scnt]
ENDIF
END
ENDIF
append to assembler report
IF Errors[Scnt] <> 0 THEN
BEGIN
set Errorflag to 1
append error report to assembler report
END
ENDIF
IF Errorflag = 0 and Skip = 0 THEN
BEGIN
place Objline on object code array
END
ENDIF
IF Skip = 1 THEN
set Skip to 0
ENDIF
increment Scnt
Breakup Sourceline[Scnt]
END {while}
place '!' on object code array
IF Errorflag = 0 THEN
transfer object code array to file
ENDIF
END {of Pass 2}
0 comments:
Post a Comment