-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPass 2
More file actions
76 lines (75 loc) · 2.44 KB
/
Copy pathPass 2
File metadata and controls
76 lines (75 loc) · 2.44 KB
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
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
void main(){
FILE *intermediate,*optab,*symtab,*output,*length,*objectcode;
char opcode[20],operand[20],label[20],mnemonic[20],code[20],value[20],textRecord[70];
int locctr,start,prgmLength,l=0,textstartAddr;
optab=fopen("optab.txt","r");
intermediate=fopen("intermediate.txt","r");
symtab=fopen("symtab.txt","r");
length=fopen("length.txt","r");
objectcode=fopen("objectcode.txt","w");
output=fopen("output.txt","w");
fscanf(intermediate,"%s%s%s",label,opcode,operand);
fprintf(output," %-7s%-7s%-7s\n",label,opcode,operand);
if(strcmp(opcode,"START")==0){
fscanf(length,"%d",&prgmLength);
start=atoi(operand);
fprintf(objectcode,"H^%s^%06d^%06d\n",label,start,prgmLength);}
fscanf(intermediate,"%d%s%s%s",&locctr,label,opcode,operand);
textstartAddr=locctr;
strcpy(textRecord,"");
while(strcmp(opcode,"END")!=0){
char objectCode[10]="";
fprintf(output,"%d%-7s%-7s%-7s ",locctr,label,opcode,operand);
if(strcmp(opcode,"BYTE")==0){
if(operand[0]=='C'&& operand[1]=='\''){
if(strcmp(operand,"C'EOF'")==0){
strcpy(objectCode,"454F46");
}
else{
for(int i=2;i<strlen(operand)-1;i++){
sprintf(objectCode+strlen(objectCode),"%02X",operand[i]);
}}}
}
else if(strcmp(opcode,"WORD")==0){
sprintf(objectCode,"%06d",atoi(operand));
}else if(strcmp(opcode,"RESB")==0){
}
else if(strcmp(opcode,"RESW")==0){
}else{
rewind(optab);
while(fscanf(optab,"%s%s",mnemonic,code)!=EOF){
if(strcmp(opcode,mnemonic)==0){
strcpy(objectCode,code);
break;}}
rewind(symtab);
while(fscanf(symtab,"%s%s",label,value)!=EOF){
if(strcmp(operand,label)==0){
sprintf(objectCode+strlen(objectCode),"%04d",atoi(value));
break;}}}
fprintf(output,"%s\n",objectCode);
if(l + strlen(objectCode)>60){
fprintf(objectcode,"T^%06d^%02X^%s\n",textstartAddr,l/2,textRecord);
strcpy(textRecord,"");
textstartAddr=locctr;
l=0;
}
if(strlen(objectCode)>0){
strcat(textRecord,objectCode);
strcat(textRecord,"^");
l+=strlen(objectCode);
}
fscanf(intermediate,"%d%s%s%s",&locctr,label,opcode,operand);}
if(l>0){
textRecord[strlen(textRecord)-1]='\0';
fprintf(objectcode,"T^%06d^%02X^%s\n",textstartAddr,l/2,textRecord);}
fprintf(objectcode,"E^%06d\n",start);
fclose(intermediate);
fclose(symtab);
fclose(optab);
fclose(output);
fclose(length);
printf("FINISHED EXECUTION!!");
}