-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathpass1.c
67 lines (67 loc) · 1.52 KB
/
pass1.c
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
#include<stdio.h>
#include<string.h>
struct estab
{
char csname[10];
char extsym[10];
int address;
int length;
}es[20];
void main()
{
char input[10],name[10],symbol[10],ch; int count=0,progaddr,csaddr,add,len;
FILE *fp1,*fp2;
fp1=fopen("INPUT.DAT","r");
fp2=fopen("ESTAB.DAT","w");
printf("\n\nEnter the address where the program has to be loaded : ");
scanf("%x",&progaddr); // TAKING THE PROGRAM ADDRESS FROM THE USER,GENERALLY IT IS DONE BY THE OS
csaddr=progaddr;
fscanf(fp1,"%s",input);
while(strcmp(input,"END")!=0)
{
if(strcmp(input,"H")==0)
{
fscanf(fp1,"%s",name);
strcpy(es[count].csname,name);
strcpy(es[count].extsym," ");
fscanf(fp1,"%x",&add);
es[count].address=add+csaddr;
fscanf(fp1,"%x",&len);
es[count].length=len;
fprintf(fp2,"%s ** %x %x\n",es[count].csname,es[count].address,es[count].length);
count++;
}
else if(strcmp(input,"D")==0)
{
fscanf(fp1,"%s",input);
while(strcmp(input,"R")!=0)
{
strcpy(es[count].csname," ");
strcpy(es[count].extsym,input);
fscanf(fp1,"%x",&add);
es[count].address=add+csaddr;
es[count].length=0;
fprintf(fp2,"** %s %x\n",es[count].extsym,es[count].address);
count++;
fscanf(fp1,"%s",input);
}
csaddr=csaddr+len;
}
else if(strcmp(input,"T")==0)
{
while(strcmp(input,"E")!=0)
fscanf(fp1,"%s",input);
}
fscanf(fp1,"%s",input);
}
fclose(fp1);
fclose(fp2);
fp2=fopen("ESTAB.DAT","r");
ch=fgetc(fp2);
while(ch!=EOF)
{
printf("%c",ch);
ch=fgetc(fp2);
}
fclose(fp2);
}