From: bylex Date: Wed, 16 Oct 2024 07:01:40 +0000 (+0200) Subject: Add support for memory keywords in assembler X-Git-Url: https://git.bylex.cz/?a=commitdiff_plain;h=874722dab66e2a5573949a5bc439c9db0480bb21;p=maturita.git Add support for memory keywords in assembler --- diff --git a/assembler.c b/assembler.c index 8f2a146..9e1731e 100644 --- a/assembler.c +++ b/assembler.c @@ -7,14 +7,15 @@ #include "assembler.h" - +uint16_t mem[65536]; struct inst_t { bool contains_instruction; uint8_t instruction_code; uint8_t params[3]; -} instruction_default = {false, 0, 0, 0, 0}; + uint16_t addr; +} instruction_default = {false, 0, 0, 0, 0, 0}; struct label_t { @@ -155,16 +156,15 @@ struct inst_t parse_line(char* line_buffer, struct label_t* labels, unsigned int token_count++; token = strtok(NULL, " "); } + inst.addr = current_addr; + memcpy(&mem[current_addr], &inst.instruction_code, 4); current_addr = current_addr + 2; return inst; } -void write_instruction(FILE** output_file, struct inst_t inst) +void write_instructions(FILE** output_file) { - if(inst.contains_instruction) - { - fwrite(&inst.instruction_code, sizeof(uint8_t), 4, *output_file); - } + fwrite(&mem, sizeof(uint16_t), 65536, *output_file); } int main(int argc, char *argv[]) @@ -236,6 +236,7 @@ int main(int argc, char *argv[]) rewind(input_file); while(fgets(line_buffer, 256, input_file)) { - write_instruction(&output_file, parse_line(line_buffer, labels, &labels_len, labels_index)); + parse_line(line_buffer, labels, &labels_len, labels_index); } + write_instructions(&output_file); }