Pass2 of Assembler
Pass2 of Assembler
To implement of pass two of pass two assembler in CS1207 SYSTEM SOFTWARE LAB usi
ng opcode
Algorithm
Start the program
Initialize all the variables
Open a file by name
fp1=fopen("assmlist.dat","w");
fp2=fopen("symtab.dat","r");
fp3=fopen("intermediate.dat","r");
fp4=fopen("optab.dat","r");
Read the content of the file
If opcode is BYTE
if(strcmp(opcode,"BYTE")==0)
Then
fprintf(fp1,"%d\t%s\t%s\t%s\t",address,label,opcode,operand);
Else if opcode is WORD
else if(strcmp(opcode,"WORD")==0)
then
fprintf(fp1,"%d\t%s\t%s\t%s\t00000%s\n",address,label,opcode,operand,a);
Else perform
else if((strcmp(opcode,"RESB")==0)(strcmp(opcode,"RESW")==0))
fprintf(fp1,"%d\t%s\t%s\t%s\n",address,label,opcode,operand);
if it is not math anything
else
fprintf(fp1,"%d\t%s\t%s\t%s\t%d0000\n",address,label,opcode,operand,code);
Finally terminate the of pass two of pass two assembler
INPUT FILES
INTERMEDIATE.DAT
** 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'EOF'
2019 C1 RESB 1
2020 ** END **
OPTAB.DAT
LDA 33
STA 44
LDCH 53
STCH 57
END *
SYMTAB.DAT
ALPHA 2012
FIVE 2015
CHARZ 2018
C1 2019
OUTPUT FILE :
ASSMLIST.DAT
** START 2000
2000 ** LDA FIVE 332015
2003 ** STA ALPHA 442012
2006 ** LDCH CHARZ 532018
2009 ** STCH C1 572019
2012 ALPHA RESW 1
2015 FIVE WORD 5 000005
2018 CHARZ BYTE C'EOF' 454f46
2019 C1 RESB 1
2020 ** END **