le compilateur super performant
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

asm_instructions.c 1.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "asm_instructions.h"
  2. char* instructions_labels[12] = {
  3. "ADD",
  4. "MUL",
  5. "SOU",
  6. "DIV",
  7. "COP",
  8. "AFC",
  9. "JMP",
  10. "JMF",
  11. "INF",
  12. "SUP",
  13. "EQU",
  14. "PRI"
  15. };
  16. void init_instruction_table(InstructionTable *table) {
  17. table->index = 0;
  18. }
  19. int add_instruction(InstructionTable *table, Instruction instruction, int arg1, int arg2, int arg3) {
  20. if (table->index >= INSTRUCTION_TABLE_SIZE) {
  21. return -1;
  22. }
  23. InstructionItem newItem;
  24. newItem.instruction = instruction;
  25. newItem.arg1 = arg1;
  26. newItem.arg2 = arg2;
  27. newItem.arg3 = arg3;
  28. table->table[table->index] = newItem;
  29. table->index++;
  30. return 0;
  31. }
  32. void write_instruction_table(InstructionTable *table, FILE *file) {
  33. for (int i = 0; i < table->index; i++) {
  34. write_instruction(&table->table[i], file);
  35. }
  36. }
  37. void write_instruction(InstructionItem *item, FILE *file) {
  38. fprintf(file, "%s %d %d %d\n", instructions_labels[item->instruction], item->arg1, item->arg2, item->arg3);
  39. }