Initial commit, can read from a list of files passed.

This commit is contained in:
2021-12-28 20:09:33 +00:00
commit 5162804270
3 changed files with 50 additions and 0 deletions
Executable
BIN
View File
Binary file not shown.
+6
View File
@@ -0,0 +1,6 @@
; comments are ignored
; This is a very simple test file for an assemblier.
mov r1, 5 ; move the immediate value 5 into r1
add r1, 5 ; add 5 into r1
int 21 ; maybe that will call some string drawing BIOS-like routine
ret ; return from 'call' if there were such a thing
+44
View File
@@ -0,0 +1,44 @@
#include <stdlib.h>
#include <stdio.h>
void print_file(char*);
int main(int argc, char* args[]) {
const char *input_files[argc - 1];
if (argc == 1) {
printf("Input files required.\n");
return -1;
}
// for (int i = 1; i < argc; i++) {
// input_files[i - 1] = args[i];
// print_file(args[i]);
// }
print_file(args[1]);
}
void print_file(char* file_path) {
FILE *file;
char* line = NULL;
size_t len = 0;
ssize_t bytes_read;
file = fopen(file_path, "r");
if (!file) {
printf("Failed to open '%s' for reading.\n", file_path);
return;
}
while((bytes_read = getline(&line, &len, file)) != -1) {
printf("%s", line);
}
printf("\n");
fclose(file);
if (line) free(line);
}