-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirstpass
73 lines (73 loc) · 1.35 KB
/
firstpass
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<stdio.h>
#include<string.h>
void main()
{
FILE *f1,*f2,*f3,*f4;
char s[100],lab[30],opcode[30],opa[30],opcode1[30],opa1[30];
int locctr,x=0;
f1=fopen("input.txt","r");
f2=fopen("opcode.txt","r");
f3=fopen("out1.txt","w");
f4=fopen("sym1.txt","w");
while(fscanf(f1,"%s%s%s",lab,opcode,opa)!=EOF)
{
if(strcmp(lab,"**")==0)
{
if(strcmp(opcode,"START")==0)
{
fprintf(f3,"%s %s %s",lab,opcode,opa);
locctr=(atoi(opa));
}
else
{
rewind(f2); // Pointing to the start of the file opcode.txt
x=0;
while(fscanf(f2,"%s%s",opcode1,opa1)!=EOF)
{
if(strcmp(opcode,opcode1)==0)
{
x=1;
}
}
if(x==1)
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
locctr=locctr+3;
}
}
}
else
{
if(strcmp(opcode,"RESW")==0)
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
fprintf(f4,"\n %d %s",locctr,lab);
locctr=locctr+(3*(atoi(opa)));
}
else if(strcmp(opcode,"WORD")==0)
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
fprintf(f4,"\n %d %s",locctr,lab);
locctr=locctr+3;
}
else if(strcmp(opcode,"BYTE")==0)
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
fprintf(f4,"\n %d %s",locctr,lab);
locctr=locctr+1;
}
else if(strcmp(opcode,"RESB")==0)
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
fprintf(f4,"\n %d %s",locctr,lab);
locctr=locctr+1;
}
else
{
fprintf(f3,"\n %d %s %s %s",locctr,lab,opcode,opa);
fprintf(f4,"\n %d %s",locctr,lab);
locctr=locctr+(atoi(opa));
}
}
}
}