Experiment 11 Implementation of Pass 1 of 2 Pass Assembler: Description of The Problem
Experiment 11 Implementation of Pass 1 of 2 Pass Assembler: Description of The Problem
Experiment 11 Implementation of Pass 1 of 2 Pass Assembler: Description of The Problem
The input file INPUT.DAT contains the assembly language statements. The OPTAB.DAT file
contains the opcodes. The memory addresses of statements as well as the statements should be
written into the file OUT.DAT. The symbols and addresses should be written to SYMTAB.DAT
Algorithm
Program
#include<stdio.h>
#include<string.h>
void main()
{
char opcode[10],operand[10],label[10], regstr[20];
int locctr,start,len,i=0,j=0;
char otp[20];
int o;
char * ptr;
fp1=fopen("INPUT.DAT","r");
fp2=fopen("SYMTAB.DAT","w");
fp3=fopen("OUT.DAT","w");
fscanf(fp1,"%s%s%s",label,opcode,operand);
if(strcmp(opcode,"START")==0)
{
start = (int)strtol(operand, NULL, 16);
locctr=start;
fprintf(fp3,"%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
else
locctr=0;
while(strcmp(opcode,"END")!=0)
{
fprintf(fp3,"%0x",locctr);
if(strcmp(label,"-")!=0)
{
fprintf(fp2,"%s\t%0x\n",label,locctr);
}
fp4=fopen("OPTAB.DAT","r");
fscanf(fp4, "%s%d", otp,&o);
while(!feof(fp4))
{
// missing code
}
fclose(fp4);
// missing code
fprintf(fp3,"\t%s\t%s\t%s\n",label,opcode,operand);
fscanf(fp1,"%s%s%s",label,opcode,operand);
}
fprintf(fp3,"%x\t%s\t%s\t%s\n",locctr, "-", "END", "-");
INPUT.DAT
- START 1000
FIRST STL RETADR
CLOOP JSUB RDREC
- LDA LENGTH
- COMP ZERO
- JEQ ENDFIL
- JSUB WRREC
- J CLOOP
ENDFIL LDA EOF
- STA BUFFER
- LDA THREE
- STA LENGTH
- JSUB WRREC
- LDL RETADR
- RSUB -
EOF BYTE C'EOF'
THREE WORD 3
ZERO WORD 0
RETADR RESW 1
LENGTH RESW 1
BUFFER RESB 4096
----------------------------------------------------- (Subroutine to read record from buffer)----------
RDREC LDX ZERO
- LDA ZERO
RLOOP TD INPUT
- JEQ RLOOP
- RD INPUT
- COMP ZERO
- JEQ EXIT
- STCH BUFFER,X
- TIX MAXLEN
- JLT RLOOP
EXIT STX LENGTH
- RSUB -
INPUT BYTE X'F1'
MAXLEN WORD 4096
--------------------------------------------------- (Subroutine to write record from buffer)-------------
WRREC LDX ZERO
WLOOP TD OUTPUT
- JEQ WLOOP
- LDCH BUFFER,X
- WD OUTPUT
- TIX LENGTH
- JLT WLOOP
- RSUB -
OUTPUT BYTE X'05'
- END -
OPTAB.DAT
STL 14
JSUB 48
LDA 00
COMP 28
JEQ 30
J 3C
STA 0C
LDL 08
RSUB 4C
LDX 04
TD E0
COMP 28
RD D8
STCH 54
TIX 2C
JLT 38
STX 10
LDCH 50
WD DC
To Do
Complete the missing code by looking into the algorithm given. Store the input assembly program
in INPUT.DAT file. Using the above program, input file INPUT.DAT and OPTAB.DAT which
contains the operation codes and machine language equivalents, obtain the intermediate file which
is stored in OUT.DAT and the file SYMTAB.DAT which contains the symbols and its addresses.
All addresses are in hexadecimal.