The Pass 1 of an assembler is responsible for analyzing the source code and preparing essential data structures for translation into machine code. It processes the source program line by line, identifying and defining symbols, literals, and their memory addresses. During this phase, a symbol table is created to store information about labels and variables, while a literal table records any constants found in the program. The location counter (LC) is used to track memory addresses as instructions and data are encountered. Additionally, Pass 1 handles pseudo-operations (assembler directives like START, END, ORIGIN) to manage memory allocation and program structure. However, it does not generate machine code; instead, it produces intermediate code and resolves forward references by marking them for resolution in Pass 2. This phase lays the groundwork for efficient translation during the second pass of the assembler.
Input file: assembly_input.txt
sum START 3000
first LDX ZERO
+LDA ZERO
LOOP ADD TABLE,X
TIX COUNT
JLT LOOP
+STA TOTAL
MULF ZERO
ADD ONE
RSUB
TABLE RESW 1000
COUNT RESW 1
ZERO WORD 0
TOTAL RESW 1
STR1 BYTE C'EOF'
STR2 BYTE X'01'
END
intermidiate.txt
3000 sum START 3000
3000 first LDX ZERO
3003 +LDA ZERO LOOP
3006 ADD TABLE,X TIX
3009 COUNT JLT LOOP
300C +STA TOTAL MULF
300F ZERO ADD ONE
3012 RSUB TABLE RESW
3015 1000 COUNT RESW
3018 1 ZERO WORD
301B 0 TOTAL RESW
301E 1 STR1 BYTE
3021 C'EOF' STR2 BYTE
3024 X'01' END BYTE
Symbol_table.txt
sum 3000
first 3000
+LDA 3003
ADD 3006
COUNT 3009
+STA 300C
ZERO 300F
RSUB 3012
1000 3015
1 3018
0 301B
1 301E
C'EOF' 3021
X'01' 3024