Saturday 17 September 2011

Experiment


Ex.No: 02
PASS ONE OF TWO PASS ASSEMBLER
AIM:
To implement pass one of a two 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 LOCCTR to the
operand value
2.2 Otherwise if there is no value in the operand field then LOCCTR 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 LOCCTR by
3
4.2.2 If opcode is “WORD”, then increment LOCCTR by 3;
4.2.3 If opcode is “BYTE”, then increment LOCCTR by 1;
4.2.4 If opcode is “RESW” then increment LOCCTR by the integer
equivalent of the operand value * 3;
4.2.5 If opcode is “RESB”, then increment LOCCTR by the integer
equivalent of the operand value
4.3 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 LOCCTR
6. Close all the files and exit
INPUT.DAT:
MAIN START 2000
BEGIN LDA NUM1
** ADD NUM2
** LDCH CHAR1
** STCH CHAR2
NUM1 WORD 5
NUM2 RESW 1
CHAR1 BYTE C'A'
CHAR2 RESB 1
** END BEGIN
OPTAB.DAT:
ADD 18
SUB 1C
MUL 20
DIV 24
LDA 00
LDB 68
LDX 04
LDCH 50
STA 0C
STB 78
STX 10
STCH 54
J 3C
JSUB 48
RSUB 4C
JEQ 30
JLT 38
JGT 34
START *
END *
SYMTAB.DAT:
BEGIN 2000
NUM1 2012
NUM2 2015
CHAR1 2018
CHAR2 2019


RESULT:
Thus pass one of a two pass assembler is implemented in C language.

0 comments:

Post a Comment