-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler.c
More file actions
executable file
·58 lines (57 loc) · 1.59 KB
/
assembler.c
File metadata and controls
executable file
·58 lines (57 loc) · 1.59 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
// Author : Vikas Adiwal
#include "build/generate_object.h"
int main(int argc, char *argv[]) {
int p_flag, s_flag, i_flag, t_flag, l_flag, h_flag;
p_flag = s_flag = i_flag = t_flag = l_flag = h_flag = 0;
while ((ch = getopt(argc, argv, "splith")) != -1) {
if (ch == 's')
s_flag = 1;
else if (ch == 'p')
p_flag = 1;
else if (ch == 'l')
l_flag = 1;
else if (ch == 'i')
i_flag = 1;
else if (ch == 't')
t_flag = 1;
else if (ch == 'h')
h_flag = 1;
else
continue;
}
const char *ext = file_ext(argv[optind]);
if(strcmp(ext,".asm") != 0) {
printf("Please provide a valid asm file. Exiting...\n");
exit(0);
}
if (optind != argc - 1) {
printUsage(argv[0]);
if (h_flag)
printHelp();
} else {
if (h_flag) {
printUsage(argv[0]);
printHelp();
} else {
generateTables(argv[optind]);
if (error_table_index < 2) {
generateObjectFile(argv[optind]);
}
if (p_flag)
printSource(argv[optind]);
if (s_flag)
printSymTab(sym_table_index);
if (i_flag)
printImmediateCode(op, argv[optind]);
if (t_flag)
printLiteralTab(lit_table_index);
if (l_flag) {
if (error_table_index < 2) {
generateLST(argv[optind]);
} else {
printf(ANSI_COLOR_RED "\nThere are errors in your code. LST File cannot be generated!!!" ANSI_COLOR_RESET "\n");
}
}
}
}
}