12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455 |
- #include "asm_instructions.h"
-
- char* instructions_labels[12] = {
- "ADD",
- "MUL",
- "SOU",
- "DIV",
- "COP",
- "AFC",
- "JMP",
- "JMF",
- "INF",
- "SUP",
- "EQU",
- "PRI"
- };
-
- void init_instruction_table(InstructionTable *table) {
- table->index = 0;
- }
-
- int add_instruction(InstructionTable *table, Instruction instruction, int arg1, int arg2, int arg3) {
- if (table->index >= INSTRUCTION_TABLE_SIZE) {
- return -1;
- }
- InstructionItem newItem;
- newItem.instruction = instruction;
- newItem.arg1 = arg1;
- newItem.arg2 = arg2;
- newItem.arg3 = arg3;
-
- table->table[table->index] = newItem;
- table->index++;
- return 0;
- }
-
- void write_instruction_table(InstructionTable *table, FILE *file) {
- for (int i = 0; i < table->index; i++) {
- write_instruction(&table->table[i], file);
- }
- }
-
- void write_instruction(InstructionItem *item, FILE *file) {
- if (item->instruction == PRI || item->instruction == JMP) {
- fprintf(file, "%s %d\n", instructions_labels[item->instruction], item->arg1);
- } else if (item->instruction == COP || item->instruction == AFC || item->instruction == JMF) {
- fprintf(file, "%s %d %d\n", instructions_labels[item->instruction], item->arg1, item->arg2);
- } else {
- fprintf(file, "%s %d %d %d\n", instructions_labels[item->instruction], item->arg1, item->arg2, item->arg3);
- }
- }
-
- int get_current_address(struct InstructionTable *table) {
- return table->index;
- }
|