75% found this document useful (4 votes)
14K views1 page

Implementation of Pass1 of The Two Pass Assembler

This document describes the algorithm for implementing Pass 1 of a two-pass assembler in C. The algorithm reads each line of code, checks for labels and symbols, determines the operation code and increments the location counter appropriately, and writes the line along with its assigned memory address to an intermediate file. It calculates the length of the program by subtracting the start address from the final location counter value.

Uploaded by

s_athya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
75% found this document useful (4 votes)
14K views1 page

Implementation of Pass1 of The Two Pass Assembler

This document describes the algorithm for implementing Pass 1 of a two-pass assembler in C. The algorithm reads each line of code, checks for labels and symbols, determines the operation code and increments the location counter appropriately, and writes the line along with its assigned memory address to an intermediate file. It calculates the length of the program by subtracting the start address from the final location counter value.

Uploaded by

s_athya
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 1

Ex no 2 IMPLEMENTATION OF PASS1 OF THE TWO PASS

ASSEMBLER

AIM:

To implement a PASS 1 of a two pass assembler, using C language.

ALGORITHM:

Step 1: Read the input line.

Step 2: Check to see if the opcode field in the input line is “START”.

1. Find if there is any operand field after START; initialize the LOCCTR
to the operand value.
2. Otherwise if there is no value in the operand field LOCCTR is set to
zero.

Step 3: Write the line to the intermediate file.

Step 4: Repeat the following for the other lines in the program until the opcode field
contains end directive.

1. If there is a symbol in the label field.


a. Check the symbol table to see is=f has already been stored over there.
If so then it is a duplicate symbol, the error message should be displayed.
b. Other wise the symbol is entered into the SYMTAB, along with the
memory address in which it is stored.
2. If there is an opcode in the opcode field
d. Search the OPTAB to see if the opcode is present, if so increment the
location counter (LOCCTR) by three.
e. i. If the opcode is WORD, increment the LOCCTR by three.
ii. If the opcode is BYTE, increment the LOCCTR by one.
iii. If the opcode is RESW, increment the LOCCTR by integer
equivalent of the operand value *3.
iv. If the opcode is RESB, increment the LOCCTR by the integer
equivalent of the operand value.
3. Write each and every line processed to the intermediate file along with the
location counters.

Step 5: Calculate the length of the program by subtracting the starting address of
program from the final value of the LOCCTR.
Step 6:Close all the opened files and exit.

You might also like