-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathabsoluteLoader.c
73 lines (67 loc) · 1.59 KB
/
absoluteLoader.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
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
FILE *OBJECTCODE,*MEMORY;
void init(){
OBJECTCODE=fopen("objectcode.txt","r");\
MEMORY=fopen("memory.txt","w");
}
int convert_hex(char a[]){
int var=0;
for(int i=0;i<strlen(a);i++){
int n=a[i];
var=var*16+(n<58?n-48:n-55);
}
return var;
}
int convert_hexc(char a){
return a<58?a-48:a-55;
}
int main(){
char DATA[100];
char HEADER[10];
int cursor=0;
init();
fscanf(OBJECTCODE,"H^%s",HEADER);
fscanf(OBJECTCODE,"T^%s",DATA);
while(DATA[0]!='E'){
char START[7],SIZE[3];
START[6]='\0';
SIZE[2]='\0';
cursor+=2;
for(int i=0;i<6;i++){
START[i]=DATA[cursor];
cursor++;
}
printf("Text Record Starting Address:%s\n",START);
cursor++;
for(int i=0;i<2;i++){
SIZE[i]=DATA[cursor];
cursor++;
}
printf("Size of text record:%s\n",SIZE);
int bytecounter=0;
while(DATA[cursor]!='\0'){
if(bytecounter%8==0){
fprintf(MEMORY,"\t");
bytecounter=0;
}
if(DATA[cursor]!='^'){
fprintf(MEMORY,"%s",DATA);
bytecounter++;
}
cursor++;
}
fprintf(MEMORY,"\n");
fscanf(OBJECTCODE,"%s",DATA);
cursor=0;
}
}
/*
objectcode.txt
==============
H^COPY^001000^001036
T^001000^1E^141033^482039^001036^281030^301548^206130^030010^2A0C10^39001
T^001E15^15^0C1036^482061^081033^4C0000^454F46^000003^000000
E^001000
*/