Fix loading memory and add simple stack test
authorbylex <mbilek06@gmail.com>
Wed, 26 Feb 2025 07:48:36 +0000 (08:48 +0100)
committerbylex <mbilek06@gmail.com>
Wed, 26 Feb 2025 07:48:36 +0000 (08:48 +0100)
interpreter.c
test_stack.o [new file with mode: 0644]
test_stack.s [new file with mode: 0644]

index cb83f35889148f6390a1da46cb1ca0a679ce5a0d..17c8333346e23ffd2f2c788996503fe1b8c22c93 100644 (file)
@@ -2,6 +2,7 @@
 #include <stdlib.h>
 #include <string.h>
 #include <stdint.h>
+#include <unistd.h>
 
 #include "tigr.h"
 
@@ -26,14 +27,14 @@ uint64_t instruction_counter = 0;
 void load_mem(char* file_name)
 {
        uint32_t current_addr = 0;
-       uint8_t* line_buffer = malloc(5);
+       uint8_t* line_buffer = malloc(4);
        FILE* input_file = fopen(file_name, "rb");
        if(!input_file)
        {
                perror("Error opening input file");
                exit(1);
        }
-       while(fgets(line_buffer, 5, input_file))
+       while(fread(line_buffer, 4, 1, input_file))
        {
         if(current_addr > 65534) break;
                memcpy(&(mem[current_addr]), line_buffer, 4);
diff --git a/test_stack.o b/test_stack.o
new file mode 100644 (file)
index 0000000..7ed3afb
Binary files /dev/null and b/test_stack.o differ
diff --git a/test_stack.s b/test_stack.s
new file mode 100644 (file)
index 0000000..0c661b7
--- /dev/null
@@ -0,0 +1,3 @@
+ldl 1 255
+pts 1
+pfs 2