0% found this document useful (0 votes)
296 views

Two Pass SIC Assembler

The two pass SIC assembler operates in two phases: 1. Pass 1 assigns addresses to symbols and statements, saves symbol addresses in the symbol table, and writes an intermediate file. 2. Pass 2 assembles machine code instructions using operation codes looked up in a table, generates data values, finishes processing directives, and writes the object code file. Key data structures used include the symbol table, operation code table, and location counter.

Uploaded by

Vidhya Mohanan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
296 views

Two Pass SIC Assembler

The two pass SIC assembler operates in two phases: 1. Pass 1 assigns addresses to symbols and statements, saves symbol addresses in the symbol table, and writes an intermediate file. 2. Pass 2 assembles machine code instructions using operation codes looked up in a table, generates data values, finishes processing directives, and writes the object code file. Key data structures used include the symbol table, operation code table, and location counter.

Uploaded by

Vidhya Mohanan
Copyright
© © All Rights Reserved
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 122

Two Pass SIC Assembler

 Pass 1 (define symbols)


 Assign addresses to all statements in the program
 Save the addresses assigned to all labels for use in Pass 2
 Perform assembler directives, including those for address assignment,
such as BYTE and RESW
 Pass 2 (assemble instructions and generate object program)
 Assemble instructions (generate opcode and look up addresses)
 Generate data values defined by BYTE, WORD
 Perform processing of assembler directives not done during Pass 1
 Write the object program and the assembly listing

1
2
Two Pass SIC Assembler
 Read from input line
 LABEL, OPCODE, OPERAND

Source
program

Intermediate Object
Pass 1 Pass 2
file codes

OPTAB SYMTAB SYMTAB

3
Assembler Data Structures
 Operation Code Table (OPTAB)
 Symbol Table (SYMTAB)
 Location Counter (LOCCTR)

OPTAB

Pass 1
Intermediate Object
file Program
Source
Pass 2
SYMTA
LOCCTR
B

4
Location Counter (LOCCTR)
 A variable that is used to help in the assignment of addresses, i.e.,
LOCCTR gives the address of the associated label.
 LOCCTR is initialized to be the beginning address specified in the
START statement.
 After each source statement is processed during pass 1, the length of
assembled instruction or data area to be generated is added to LOCCTR.

5
Operation Code Table (OPTAB)
 Contents:
 Mnemonic operation codes (as the keys)
 Machine language equivalents
 Instruction format and length
 Note: SIC/XE has instructions of different lengths

 During pass 1:
 Validate operation codes
 Find the instruction length to increase LOCCTR

 During pass 2:
 Determine the instruction format
 Translate the operation codes to their machine language equivalents

 Implementation: a static hash table (entries are not normally added to or deleted
from it)
 Hash table organization is particularly appropriate

6
COPY 1000

SYMTAB
FIRST 1000
CLOOP 1003
ENDFIL 1015
EOF 1024
THREE 102D
 Contents: ZERO 1030
 Label name RETADR 1033
 Label address LENGTH 1036
BUFFER 1039
 Flags (to indicate error conditions)
RDREC 2039
 Data type or length

 During pass 1:
 Store label name and assigned address (from LOCCTR) in SYMTAB

 During pass 2:
 Symbols used as operands are looked up in SYMTAB

 Implementation:
 a dynamic hash table for efficient insertion and retrieval
 Should perform well with non-random keys (LOOP1, LOOP2).

7
Fig. 2.2 (1) Program with Object
code

8
Fig. 2.2 (2) Program with Object
code

9
Fig. 2.2 (3) Program with Object
code

10
Figure 2.1 (Pseudo code Pass 1)

15
Figure 2.1 (Pseudo code Pass 1)

16
Figure 2.1 (Pseudo code Pass 2)

17
Figure 2.1 (Pseudo code Pass 2)

18
Loc Source Statement
PASS -1 1000 COPY START 1000 COPY FILE FROM INPUT TO OUTPUT
1000 FIRST STL RETADR SAVE RETURN ADDRESS
1003 CLOOP JSUB RDREC READ INPUT RECORD
1006 LDA LENGTH TEST FOR EOF (LENGTH = 0)
begin 1009 COMP ZERO
read first input line 100C JEQ ENDFILEXIT IF EOF FOUND
if OPCODE = 'START' then 1000F JSUB WRRECWRITE OUTPUT RECORD
begin
1012 J CLOOP LOOP
save #[OPERAND] as starting address
initialized LOCCTR to starting address 1015 ENDFIL LDA EOF INSERT END OF FILE MARKER
write line to intermediate file 1018 STA BUFFER
read next input line 101B LDA THREE SET LENGTH = 3
end {if START} 101E STA LENGTH
else 1021 JSUB WRRECWRITE EOF
initialized LOCCTR to 0
1024 LDL RETADR GET RETURN ADDRESS
1027 RSUB RETURN TO CALLER
102A EOF BYTE C’EOF’
102D THREE WORD 3
1030 ZERO WORD 0
1033 RETADR RESW 1
1036 LENGTHRESW 1 LENGTH OF RECORD
1039 BUFFER RESB 4096 4096-BYTE BUFFER AREA
.
. SUBROUTINE TO READ RECORD INTO BUFFER
.
2039 RDREC LDX ZERO CLEAR LOOP COUNTER

.
. SUBROUTINE TO WRITE RECORD FROM BUFFER
.
2061 WRREC LDX ZERO CLEAR LOOP COUNTER
.
.

END FIRST
while OPCODE != 'END' do 1000 COPY START 1000 COPY FILE FROM INPUT TO OUTPUT
begin
1000 FIRST STL RETADR SAVE RETURN ADDRESS
if this is not a comment line then
begin 1003 CLOOP JSUB RDREC READ INPUT RECORD
if there is a symbol in the LABEL field then 1006 LDA LENGTH TEST FOR EOF (LENGTH = 0)
begin 1009 COMP ZERO
search SYMTAB for LABEL 100C JEQ ENDFILEXIT IF EOF FOUND
if found then 1000F JSUB WRRECWRITE OUTPUT RECORD
set error flag (duplicate symbol)
1012 J CLOOP LOOP
else
insert (LABEL, LOCCTR) into SYMTAB 1015 ENDFIL LDA EOF INSERT END OF FILE MARKER
end {if symbol} 1018 STA BUFFER
search OPTAB for OPCODE 101B LDA THREE SET LENGTH = 3
if found then 101E STA LENGTH
add 3 {instruction lengh} to LOCCTR 1021 JSUB WRRECWRITE EOF
else if OPCODE = 'WORD' then
1024 LDL RETADR GET RETURN ADDRESS
add 3 to LOCCTR
else if OPCODE = 'RESW' then 1027 RSUB RETURN TO CALLER
add 3 * #[OPERAND] to LOCCTR 102A EOF BYTE C’EOF’
else if OPCODE = 'RESB' then 102D THREE WORD 3
add #[OPERAND] to LOCCTR 1030 ZERO WORD 0
else if OPCODE = 'BYTE' then 1033 RETADR RESW 1
begin
1036 LENGTHRESW 1 LENGTH OF RECORD
find length of constant in bytes
add length to LOCCTR 1039 BUFFER RESB 4096 4096-BYTE BUFFER AREA
end {if BYTE} .
else . SUBROUTINE TO READ RECORD INTO BUFFER
set error flag (invalid operation code) .
end {if not a comment} 2039 RDREC LDX ZERO CLEAR LOOP COUNTER
write line to intermediate file

read next input line
end {while not END} .
write last line to intermediate file . SUBROUTINE TO WRITE RECORD FROM BUFFER
save (LOCCTR - starting address) as program length .
end 2061 WRREC LDX ZERO CLEAR LOOP COUNTER
.
.

END FIRST
ASS -2
Loc Source Statement Object Code
1000 COPY START 1000 COPY FILE FROM INPUT TO OUTPUT
1000 FIRST STL RETADR SAVE RETURN ADDRESS 141033
1003 CLOOP JSUB RDREC READ INPUT RECORD 482039
1006 LDA LENGTH TEST FOR EOF (LENGTH = 0) 001036
1009 COMP ZERO 281030
100C JEQ ENDFILEXIT IF EOF FOUND 301015
1000F JSUB WRRECWRITE OUTPUT RECORD 482061
1012 J CLOOP LOOP 3C1003
begin 1015 ENDFIL LDA EOF INSERT END OF FILE MARKER 00102A
1018 STA BUFFER 0C1039
read first input file {from intermediate 101B LDA THREE SET LENGTH = 3 00102D
file} 101E STA LENGTH 0C1036
1021 JSUB WRRECWRITE EOF 482061
if OPCODE = 'START' then 1024 LDL RETADR GET RETURN ADDRESS 081033
begin 1027 RSUB RETURN TO CALLER 4C000
write listing line 102A EOF BYTE C’EOF’ 454F46
102D THREE WORD 3 000003
read next input line 1030 ZERO WORD 0 000000
end {if START} 1033 RETADR RESW 1
write header record to object program 1036 LENGTHRESW 1 LENGTH OF RECORD
1039 BUFFER RESB 4096 4096-BYTE BUFFER AREA
initialized first Text record .
. SUBROUTINE TO READ RECORD INTO BUFFER
.
2039 RDREC LDX ZERO CLEAR LOOP COUNTER 041030

.
. SUBROUTINE TO WRITE RECORD FROM BUFFER
.
2061 WRREC LDX ZERO CLEAR LOOP COUNTER 041030
.
.

END FIRST

You might also like