Compare commits
No commits in common. "feb34cd40972b68545092b703af8577694d07144" and "6a7f2a5098fe3e32d2391227f99c3aab6d552fda" have entirely different histories.
feb34cd409
...
6a7f2a5098
6
Makefile
6
Makefile
@ -1,5 +1,7 @@
|
||||
all:
|
||||
gcc ./main.c -std=c99 -o tasm
|
||||
gcc ./main.c -std=c99
|
||||
./a.out
|
||||
|
||||
d:
|
||||
gcc -g -std=c99 ./main.c -o tasm
|
||||
gcc -g -std=c99 ./main.c
|
||||
gdb ./a.out
|
||||
|
40
main.c
40
main.c
@ -67,36 +67,12 @@ void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
int main() {
|
||||
FILE *dest_asm = fopen("assembly.txt", "w");
|
||||
FILE *src_asm = fopen("src.asm", "r");
|
||||
unsigned int size=0;
|
||||
|
||||
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
|
||||
fprintf(dest_asm,"00000\n");
|
||||
char in_asm[64];
|
||||
char out_asm[27];
|
||||
|
||||
@ -105,7 +81,10 @@ int main(int argc, char **argv) {
|
||||
int hex_in1;
|
||||
int hex_out;
|
||||
|
||||
while(fgets(in_asm, sizeof(in_asm), src_asm)) {
|
||||
fgets(in_asm, 64, src_asm);
|
||||
|
||||
|
||||
while(!feof(src_asm)) {
|
||||
hex_op = 0;
|
||||
hex_in0 = 0;
|
||||
hex_in1 = 0;
|
||||
@ -122,6 +101,7 @@ int main(int argc, char **argv) {
|
||||
fprintf(dest_asm,"%.5x \n", hex_out);
|
||||
// Write the hex to a file
|
||||
|
||||
fgets(in_asm, 64, src_asm);
|
||||
size++;
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user