1. The document describes the algorithm for implementing pass one of a two-pass assembler. It reads source code lines and determines locations in memory for instructions and data by incrementing the location counter (LOCCTR). It also builds a symbol table by inserting labels and their memory locations.
2. The key steps are reading lines from an input file, searching for labels and symbols to insert into the symbol table, looking up opcodes to determine instruction lengths, and incrementing LOCCTR accordingly for each line to calculate memory locations.
3. It writes the lines along with their calculated memory locations to an output file, and outputs the length of the assembled program.
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
290 views
Pass 2 Assembler
1. The document describes the algorithm for implementing pass one of a two-pass assembler. It reads source code lines and determines locations in memory for instructions and data by incrementing the location counter (LOCCTR). It also builds a symbol table by inserting labels and their memory locations.
2. The key steps are reading lines from an input file, searching for labels and symbols to insert into the symbol table, looking up opcodes to determine instruction lengths, and incrementing LOCCTR accordingly for each line to calculate memory locations.
3. It writes the lines along with their calculated memory locations to an output file, and outputs the length of the assembled program.
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4
IMPLEMENTATION OF PASS ONE OF A TWO PASS ASSEMBLER
AIM OF THE EXPERIMENT:
To write a program to implement pass one of a two pass assembler. ALGORITHM 1.begin 2 read first input line; 3 if OPCODE = 'START' then begin i. save #[OPERAND] as starting address ii. initialized LOCCTR to starting address iii. write line to intermediate file iv. read next input line end {if START} 4 else initialized LOCCTR to 0 5 while OPCODE != 'END' do begin a. i. if this is not a comment line then ii. begin iii. if there is a symbol in the LABEL field then begin 1. search SYMTAB for LABEL 2. if found then 3. set error flag (duplicate symbol) 4. else 5. insert (LABEL, LOCCTR) into SYMTAB end {if symbol} iv. search OPTAB for OPCODE v. if found then add 3 {instruction length} to LOCCTR vi. else if OPCODE = 'WORD' then add 3 to LOCCTR vii. else if OPCODE = 'RESW' then add 3 * #[OPERAND] to LOCCTR viii. else if OPCODE = 'RESB' then add #[OPERAND] to LOCCTR ix. else if OPCODE = 'BYTE' then begin 1. find length of constant in bytes 2. add length to LOCCTR end {if BYTE} x. else set error flag (invalid operation code) end {if not a comment} 6 write line to intermediate file 7 read next input line 8 end {while not END} 9 write last line to intermediate file 10 save (LOCCTR - starting address) as program length 11 end c) Program: #include<stdio.h> #include<conio.h> #include<string.h>
** START 2000 ** LDA FIVE ** STA ALPHA ** LDCH CHARZ ** STCH C1 ALPHA RESW 1 FIVE WORD 5 CHARZ BYTE C'Z' C1 RESB 1 ** END ** Dr.NNCE I T / V Sem SS Lab - LM
14 optab.txt
START * LDA 03 STA 0f LDCH 53 STCH 57 END *
OUTPUT FILES:
The length of the program is 20 symtab.txt ALPHA 2012 FIVE 2015 CHARZ 2018 C1 2019
ouput.txt ** START 2000 2000 ** LDA FIVE 2003 ** STA ALPHA 2006 ** LDCH CHARZ 2009 ** STCH C1 2012 ALPHA RESW 1 2015 FIVE WORD 5 2018 CHARZ BYTE C'Z' 2019 C1 RESB 1 2020 ** END **