-
Notifications
You must be signed in to change notification settings - Fork 40
Expand file tree
/
Copy pathmain.c
More file actions
40 lines (31 loc) · 689 Bytes
/
Copy pathmain.c
File metadata and controls
40 lines (31 loc) · 689 Bytes
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
#include "myas.h"
int main(int argc, char* argv[])
{
char ifname[20];
char ofname[20];
char op[4];
char args[256];
char* mcode;
if(argc < 3){
printf("Usage: myas input_file output_file\n");
return 0;
}
strcpy(ifname, argv[1]);
strcpy(ofname, argv[2]);
FILE *ifp = fopen(ifname, "r");
FILE *ofp = fopen(ofname, "w");
mcode = (char*) malloc (sizeof(char)*20);
while (!feof(ifp)){
fscanf(ifp, "%s %s\n", op, args);
// translate assembly into machine-code
if(!instr_trans(op, args, mcode)){
printf("Error: %s %s cannot be translated\n", op, args);
continue;
}
fprintf(ofp, "%s\n", mcode);
}
free(mcode);
fclose(ifp);
fclose(ofp);
return 1;
}