This repository has been archived by the owner on Sep 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.c
69 lines (59 loc) · 1.82 KB
/
main.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
/*
* Main file
*/
#include "lc3asm.h"
int main(int argc, char *argv[])
{
char *p;
files f;
if (argc == 2)
{
//open input file and output files with appropriate names/extensions in the source file directory
strcpy(f.infilename, argv[1]);
p = strstr(f.infilename, ".asm");
if (p == NULL)
{
printf("Please input a file in assembly format\n");
return 1;
}
else
{
strcpy(f.outhexfilename, f.infilename);
p = strstr(f.outhexfilename, ".asm");
strcpy(p, "_hex.bin");
strcpy(f.outbinfilename, f.infilename);
p = strstr(f.outbinfilename, ".asm");
strcpy(p, ".bin");
strcpy(f.symfilename, f.infilename);
p = strstr(f.symfilename, ".asm");
strcpy(p, ".sym");
f.in = fopen(f.infilename, "r");
if (f.in == NULL)
{
printf("Error while opening input file \"%s\"\n", f.infilename);
return 1;
}
f.outhex = fopen(f.outhexfilename, "w");
f.outbin = fopen(f.outbinfilename, "w");
f.symfile = fopen(f.symfilename, "w");
if (f.outhex == NULL || f.outbin == NULL || f.symfile == NULL)
{
printf("Error while opening output files\n");
printf("You possibly don't have write permissions for the source directory.\n");
return 1;
}
}
}
else
{
printf("Usage: %s filename\n", argv[0]);
return 1;
}
//call the main assembler function
assemble(&f);
fclose(f.in);
fclose(f.outhex);
fclose(f.outbin);
fclose(f.symfile);
return 0;
}