Compare commits

...

2 Commits

Author SHA1 Message Date
nova
feb34cd409 command line arguments, cleanup 2024-03-17 17:16:58 +01:00
nova
67c050abbc command line arguments, cleanup 2024-03-17 17:16:23 +01:00
2 changed files with 32 additions and 14 deletions

View File

@ -1,7 +1,5 @@
all:
gcc ./main.c -std=c99
./a.out
gcc ./main.c -std=c99 -o tasm
d:
gcc -g -std=c99 ./main.c
gdb ./a.out
gcc -g -std=c99 ./main.c -o tasm

40
main.c
View File

@ -67,12 +67,36 @@ void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){
}
int main() {
FILE *dest_asm = fopen("assembly.txt", "w");
FILE *src_asm = fopen("src.asm", "r");
unsigned int size=0;
int main(int argc, char **argv) {
fprintf(dest_asm,"00000\n");
FILE *dest_asm;
FILE *src_asm;
if (argc > 2) {
for (int i = 1 ; i < argc; i++) {
if (strcmp("-i", argv[i]) == 0 || strcmp("--input", argv[i]) == 0) {
src_asm = fopen(argv[i+1], "r");
i=i+1;
} else if (strcmp("-o", argv[i]) == 0 || strcmp("--output", argv[i]) == 0) {
dest_asm = fopen(argv[i+1], "w");
i=i+1;
} else if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) {
printf("Usage: tasm [options] file...\n");
printf("Options:\n");
printf("-h,--help Prints this information\n");
printf("-i,--input <arg> Path of input file\n");
printf("-o,--output <arg> Path of output file\n");
return 0;
} else {
printf("unknown argument: %s\n", argv[i]);
return 1;
}
}
} else {
printf("tasm: no input file\n");
return 1;
}
unsigned int size=0; //keeps the size of the assembled program
char in_asm[64];
char out_asm[27];
@ -81,10 +105,7 @@ int main() {
int hex_in1;
int hex_out;
fgets(in_asm, 64, src_asm);
while(!feof(src_asm)) {
while(fgets(in_asm, sizeof(in_asm), src_asm)) {
hex_op = 0;
hex_in0 = 0;
hex_in1 = 0;
@ -101,7 +122,6 @@ int main() {
fprintf(dest_asm,"%.5x \n", hex_out);
// Write the hex to a file
fgets(in_asm, 64, src_asm);
size++;
}