(* 31V4 Assignment 2 - PD subset assembler *) (* Written by: J.G.Harston, (C)HCE *) (* Pass_2 module. Entry at pass2 to do the second pass of the source file. *) IMPLEMENTATION MODULE Pass_2; FROM FileSystem IMPORT Eof, Reset; FROM InOut IMPORT WriteString, WriteLn, WriteOct, in; FROM Parser IMPORT Do_This_Line; FROM Symbols IMPORT init_list, get_label, Label; VAR line_num:INTEGER; error:BOOLEAN; PROCEDURE pass2; BEGIN WriteString('Pass 2'); WriteLn; Reset(in); (* Rewind to start of file *) line_num=1; REPEAT error:=Do_This_Line(2,line_num); line_num:=line_num+1; UNTIL Eof(in) OR error; (* Stop at end or error *) DoListing; (* Display the symbol table *) END pass2; PROCEDURE DoListing; VAR num,loop,colm,value:INTEGER; lbl:Label; end:BOOLEAN; BEGIN WriteLn; colm:=1; num:=0 init_list(num); (* Get the number of entries *) IF num=0 THEN WriteString('No labels defined.'); WriteLn; RETURN; END; WriteString('Symbol table:'); WriteLn; WriteLn; FOR loop:=1 TO num DO (* Display all the entries *) end:=get_label(lbl,value); (* Get an entry *) disp(lbl); (* Display it with padding spaces *) WriteOct(value,6); WriteString(' '); colm:=colm+1; (* Move to next column *) IF colm=4 THEN (* We're in column four, it's time for *) colm:=1; WriteLn; (* another line *) END; END; IF colm<>1 THEN WriteLn; END; (* Do another line if needed *) END DoListing; PROCEDURE disp(lbl:Label); (* Display the label with padding spaces in a field of 8 characters *) VAR ptr,loop:INTEGER; BEGIN ptr:=0; LOOP WriteString(lbl[ptr]); ptr:=ptr+1; IF ptr=7 THEN EXIT; END; IF lbl[ptr]=0c THEN EXIT; END; END; FOR loop:=ptr TO 8 DO WriteString(' '); END; END disp; END Pass_2