0% found this document useful (0 votes)
201 views

Pass Two of Two Pass Assembler Program

This program contains two functions - a main function and a wordcount function. The main function opens input files, scans the lines, and outputs an assembled program based on the line format. It checks for 2, 3, or 4 word lines and outputs in a specific format using additional files for opcodes and symbols. The wordcount function counts the number of words on each line of an input file and stores the counts in an array used by the main function.

Uploaded by

Puneet Mehta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
201 views

Pass Two of Two Pass Assembler Program

This program contains two functions - a main function and a wordcount function. The main function opens input files, scans the lines, and outputs an assembled program based on the line format. It checks for 2, 3, or 4 word lines and outputs in a specific format using additional files for opcodes and symbols. The wordcount function counts the number of words on each line of an input file and stores the counts in an array used by the main function.

Uploaded by

Puneet Mehta
Copyright
© Attribution Non-Commercial (BY-NC)
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 4

PASS TWO OF TWO PASS ASSEMBLER

PROGRAM:
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
int count[20];
void main()
{
FILE *f1,*f2,*f3;
int lno,f,adr,adr1;
char mne[10],op[10],op1[10],lbl[10];
char lbval[10],label[10],opval[10];
void wordcount();
clrscr();
printf("\nWORD COUNT FOR INPUT PROGRAM\n");
wordcount();
f1=fopen("INPUT.c","r");
printf("\nOUTPUT\n\n");
lno=1;
while(!feof(f1))
{
if(count[lno]==2)
{
fscanf(f1,"%x\t%s\n",&adr,&mne);
printf("%x\t\n",adr);
}
if(count[lno]==4)
{
fscanf(f1,"%x%s%s%s",&adr,lbl,mne,op);
if(strcmp(mne,"WORD")==0)
printf("%x\t00\t000%d\n",adr,atoi(op));
else if(strcmp(mne,"BYTE")==0)
printf("%x\t0%d\n",adr,atoi(op));
}
if(count[lno]==3)
{
fscanf(f1,"%x%s%s\n",&adr,mne,op);
f3=fopen("OPCODE.c","r");
while(!feof(f3))
{
fscanf(f3,"%s%s\n",op1,opval);
if((strcmp(mne,op1))==0)
printf("%x\t%d\t",adr,atoi(opval));
}
fclose(f3);

f2=fopen("SYMTAB.c","r");
while(!feof(f2))
{
fscanf(f2,"%x%s\n",&adr1,label);
if(strcmp(op,label)==0)
printf("%x\t\n",adr1);
}
fclose(f2);
}
lno+=1;
}
fclose(f3);
getch();
}
void wordcount()
{
FILE *f1;
char c;
int word=0,i=1;
f1=fopen("INPUT.C","r");
c=fgetc(f1);
while(c!=EOF)
{
if(c==' ')
word+=1;
if(c=='\n')
{
word=word+1;
count[i]=word;
printf("\nNo. of words in linenumber %d : %d",i,word);
i+=1;
word=0;
}
c=fgetc(f1);
}
fclose(f1);
}

INPUT:
INPUT.C
1000 LDA FIRST
1003 ADD SECOND
1006 STA THIRD
1009 FIRST WORD 5
100C SECOND WORD 5
100F THIRD RESW 1
1012 END
OPCODE.C
LDA 10
ADD 20
STA 30
SYMTAB.C
1009 FIRST
100C SECOND
100F THIRD

OUTPUT:
WORDCOUNT FOR INPUT PROGRAM
No. of words in linenumber 1:3
No. of words in linenumber 2:3
No. of words in linenumber 3:3
No. of words in linenumber 4:4
No. of words in linenumber 5:4
No. of words in linenumber 6:4
OUTPUT
1000
1003
1006
1009
100C

10
20
30
00
00

1009
100C
100F
0005
0005

You might also like