-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathassembler.c
More file actions
45 lines (37 loc) · 807 Bytes
/
assembler.c
File metadata and controls
45 lines (37 loc) · 807 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
41
42
43
44
45
#include "stdio.h"
#include "stdlib.h"
#include "strings.c"
#include "y.tab.c"
#include "lex.yy.c"
#define OUTPUT_FILE_NAME "o.rom"
FILE *output;
void showHelp() {
printf("Usage: \n");
printf("\tgasm [filename]\n");
}
int main(int args, char **argv) {
printf("Grog Virtual Machine Assembler\n");
if (args < 2) {
showHelp();
return 1;
}
char *filename = argv[1];
char *outputFileName = args > 2 ? argv[2] : OUTPUT_FILE_NAME;
printf("Parsing %s\n", filename);
//int yydebug = 1;
yyin = fopen(filename, "r");
output = fopen(outputFileName, "wb");
yyparse();
fclose(yyin);
fclose(output);
return 0;
}
void hcf() {
fputc(0x00, output);
}
void load() {
fputc(0x01, output);
}
void store() {
fputc(0x01, output);
}