No Description
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.

tab_instruc.c 1.6KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. #include "tab_instruc.h"
  2. int current_index = 0;
  3. struct operation_t tab_op[MAXTAILLE];
  4. void add_operation(enum opcode_t opcode, int arg1, int arg2, int arg3){
  5. if (current_index == MAXTAILLE){
  6. printf("Taillemax tableau operations atteinte\n");
  7. }
  8. else{
  9. struct operation_t new_op = {opcode, arg1, arg2, arg3};
  10. tab_op[current_index] = new_op;
  11. current_index++;
  12. }
  13. }
  14. char * get_asm_line_from_op(struct operation_t op){
  15. char * buffer = malloc(sizeof(char)*200);
  16. switch (op.opcode){
  17. case (ADD):
  18. sprintf(buffer,"ADD %d %d %d\n",op.arg1, op.arg2, op.arg3);
  19. break;
  20. case (MUL):
  21. sprintf(buffer,"MUL %d %d %d\n",op.arg1, op.arg2, op.arg3);
  22. break;
  23. case (SOU):
  24. sprintf(buffer,"SOU %d %d %d\n",op.arg1, op.arg2, op.arg3);
  25. break;
  26. case (DIV):
  27. sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
  28. break;
  29. case (COP):
  30. sprintf(buffer,"COP %d %d\n",op.arg1, op.arg2);
  31. break;
  32. case (AFC):
  33. sprintf(buffer,"AFC %d %d\n",op.arg1, op.arg2);
  34. break;
  35. case (JMP):
  36. sprintf(buffer,"JMP %d\n",op.arg1);
  37. break;
  38. case (JMF):
  39. sprintf(buffer,"JMF %d %d\n",op.arg1, op.arg2);
  40. break;
  41. case (INF):
  42. sprintf(buffer,"INF %d %d %d\n",op.arg1, op.arg2, op.arg3);
  43. break;
  44. case (SUP):
  45. sprintf(buffer,"SUP %d %d %d\n",op.arg1, op.arg2, op.arg3);
  46. break;
  47. case (EQU):
  48. sprintf(buffer,"DIV %d %d %d\n",op.arg1, op.arg2, op.arg3);
  49. break;
  50. case (PRI):
  51. sprintf(buffer,"PRI %d\n",op.arg1);
  52. break;
  53. }
  54. return buffer;
  55. }
  56. void create_asm(){
  57. FILE * output = fopen("output.txt","w");
  58. for (int i = 0; i < current_index; i++){
  59. char * line = get_asm_line_from_op(tab_op[i]);
  60. fputs(line, output);
  61. free(line);
  62. }
  63. }