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.5KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. if (item->instruction == PRI || item->instruction == JMP) {
  39. fprintf(file, "%s %d\n", instructions_labels[item->instruction], item->arg1);
  40. } else if (item->instruction == COP || item->instruction == AFC || item->instruction == JMF) {
  41. fprintf(file, "%s %d %d\n", instructions_labels[item->instruction], item->arg1, item->arg2);
  42. } else {
  43. fprintf(file, "%s %d %d %d\n", instructions_labels[item->instruction], item->arg1, item->arg2, item->arg3);
  44. }
  45. }
  46. int get_current_address(struct InstructionTable *table) {
  47. return table->index;
  48. }