-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathabsolute loader.c
114 lines (111 loc) · 2.57 KB
/
absolute loader.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <stdio.h>
#include <string.h>
char input[10], label[10], ch1, ch2;
int addr, w = 0, start, ptaddr, l, length = 0, end, count = 0, k, taddr, address, i = 0;
FILE *fp1, *fp2;
void check();
void main()
{
fp1 = fopen("abc.txt", "r");
fp2 = fopen("Absout.txt", "w");
fscanf(fp1, "%s", input);
printf("\n\nABSOLUTE LOADER\n");
fprintf(fp2, "\n-------------------------------------------------------\n");
fprintf(fp2, "MEMORY ADDRESS\t\t\tCONTENTS");
fprintf(fp2, "\n-------------------------------------------------------\n");
while (strcmp(input, "E") != 0)
{
if (strcmp(input, "H") == 0)
{
fscanf(fp1, "%s %x %x %s", label, &start, &end, input);
address = start;
}
else if (strcmp(input, "T") == 0)
{
l = length;
ptaddr = addr;
fscanf(fp1, "%x %x %s", &taddr, &length, input);
addr = taddr;
if (w == 0)
{
ptaddr = address;
w = 1;
}
for (k = 0; k < (taddr - (ptaddr + l)); k++)
{
address = address + 1;
fprintf(fp2, "xx");
count++;
if (count == 4)
{
fprintf(fp2, " ");
i++;
if (i == 4)
{
fprintf(fp2, "\n\n%x\t\t", address);
i = 0;
}
count = 0;
}
}
if (taddr == start)
fprintf(fp2, "\n\n%x\t\t", taddr);
fprintf(fp2, "%c%c", input[0], input[1]);
check();
fprintf(fp2, "%c%c", input[2], input[3]);
check();
fprintf(fp2, "%c%c", input[4], input[5]);
check();
fscanf(fp1, "%s", input);
}
else
{
fprintf(fp2, "%c%c", input[0], input[1]);
check();
fprintf(fp2, "%c%c", input[2], input[3]);
check();
fprintf(fp2, "%c%c", input[4], input[5]);
check();
fscanf(fp1, "%s", input);
}
}
fprintf(fp2, "\n-------------------------------------------------------\n");
fclose(fp1);
fclose(fp2);
printf("\n\n The contents of output file:\n");
fp2 = fopen("Absout.txt", "r");
ch2 = fgetc(fp2);
while (ch2 != EOF)
{
printf("%c", ch2);
ch2 = fgetc(fp2);
}
fclose(fp2);
}
void check()
{
count++;
address++;
taddr = taddr + 1;
if (count == 4)
{
fprintf(fp2, " ");
i++;
if (i == 4)
{
fprintf(fp2, "\n\n%x\t\t", taddr);
i = 0;
}
count = 0;
}
}
/*
input.txt
---------
H COPY 001000 00107A
T 001000 1E 141033 482039 001036 281030 301015 482061 3C1003 00102A 0C1039 00102D
T 00101E 15 0C1036 482061 081033 4C0000 454F46 000003 000000
T 001047 1E 041030 001030 E0205D 30203F D8205D 281030 302057 549039 2C205E 38203F
T 001077 1C 101036 4C0000 000000 001000 041030 E02079 302064 509039 DC2079 2C1036
E 001000
*/