You are on page 1of 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