Saturday 17 September 2011

SINGLE PASS ASSEMBLER


Ex.No: 04
SINGLE PASS ASSEMBLER
AIM:
To implement a single pass assembler in C language.
ALGORITHM:
1. Open and Read the input file
2. If the input line has the opcode “START” do the following
2.1 Find if there is any operand field after “START”, initialize the LC to the operand
value
2.2 Otherwise if there is no value in the operand field then LC is set to 0
3. Write the input line to the intermediate file
4. Do the following steps until the opcode is END
4.1 Check the Symbol table, if the symbol is not available then enter that symbol into
the SYMTAB, along with the memory address in which it is stored. Otherwise, the
error message should be displayed
4.2 If there is a opcode
4.2.1 If opcode is present in the OPTAB, then increment the LC by 3 and
Start writing the location counter, opcode and operand fields of the
corresponding statement to the output file, along with the object code.
4.2.2 If opcode is “WORD”, then increment LC by 3;
4.2.3 If opcode is “BYTE”, then increment LC by 1;
4.2.4 If opcode is “RESW” then increment LC by the integer equivalent
of the operand value * 3;
4.2.5 If opcode is “RESB”, then increment LC by the integer equivalent
of the operand value
4.2.6 If there is no symbol/label in the operand field, then the operand
address is assigned as zero and it is assembled with the object code of the
instruction
4.2.7 Write the processed lines in the intermediate file along with their
location counters
5. To find the length of the program, Subtract the starting address of the program from the
final value of the LC
6. Close all the files and exit
INPUT.DAT
COPY START 1000
RETADR RESW1
BUFFER RESB 4
EOF BYTE C`EOF`
$ . $
FIRST STA RETADR
$ STL BUFFER
$ J FIRST
$ END START
RESULT:
Thus single pass assembler is implemented in C language.