--- /dev/null
+#include <stdio.h>
+#include <string.h>
+#include <stdbool.h>
+#include <stdlib.h>
+#include <stdint.h>
+
+#include "assembler.h"
+
+
+
+struct inst_t
+{
+ bool contains_instruction;
+ uint8_t instruction_code;
+ uint8_t params[3];
+} instruction_default = {false, 0, 0, 0, 0};
+
+void parse_line(FILE** input_file)
+{
+ char line_buffer[256];
+
+ int token_count = 0;
+ char* token;
+ struct inst_t inst = instruction_default;
+
+ fgets(line_buffer, 256, *input_file);
+
+ if(line_buffer[0] == ';')
+ {
+ return;
+ }
+ else
+ {
+ inst.contains_instruction = true;
+ }
+
+ token = strtok(line_buffer, " ");
+ while(token)
+ {
+ switch(token_count)
+ {
+ case 0:
+ // current token is instruction code
+ uint8_t i = 0;
+ while(i < N_INSTRUCTIONS - 1)
+ {
+ if(strcmp(token, opcodes_strings[i]) == 0)
+ {
+ inst.instruction_code = i;
+ break;
+ }
+ i++;
+ }
+ break;
+ case 1:
+ // current token is first parameter
+ inst.params[0] = (uint8_t)atoi(token);
+ break;
+ case 2:
+ // current token is second parameter
+ uint16_t token_int = atoi(token);
+ inst.params[1] = token_int;
+ break;
+ case 3:
+ // current token is third parameter
+ break;
+ }
+ token_count++;
+ token = strtok(NULL, " ");
+ }
+}
+
+int main(int argc, char *argv[])
+{
+
+ if(argc <= 2 || argc >= 4)
+ {
+ printf("Usage: %s <input file> <output file>\n", argv[0]);
+ return 1;
+ }
+
+ FILE* input_file = fopen(argv[1], "r");
+ if(!input_file)
+ {
+ perror("Cannot open input file for reading\n");
+ return 1;
+ }
+
+ FILE* output_file = fopen(argv[2], "w");
+ if(!output_file)
+ {
+ perror("Cannot open output file for writing\n");
+ return 1;
+ }
+ while(!feof(input_file))
+ {
+ parse_line(&input_file);
+ }
+}
--- /dev/null
+#include "common.h"
+
+char opcodes_strings[N_INSTRUCTIONS][4] = {"nop", "inc", "dec", "lod", "ldl", "sav", "swp", "jmp", "jez", "hlt", "pts", "pfs"};