decode.h 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /*
  2. * Giovanni Agosta, Andrea Di Biagio
  3. * Politecnico di Milano, 2007
  4. *
  5. * decode.h
  6. * Formal Languages & Compilers Machine, 2007/2008
  7. *
  8. */
  9. #ifndef _DECODE_H
  10. #define _DECODE_H
  11. #include <stdio.h>
  12. #include "getbits.h"
  13. #define FORMAT_TER 0
  14. #define FORMAT_BIN 1
  15. #define FORMAT_UNR 2
  16. #define FORMAT_CC 3
  17. typedef struct _instr {
  18. int opcode;
  19. int dest;
  20. int src1;
  21. int src2;
  22. int addr;
  23. int imm;
  24. int func;
  25. int format;
  26. } decoded_instr;
  27. /*
  28. * Formats ([..] optional elements, default at 0):
  29. * opcode dest src1 src2 [func]
  30. * opcode dest src1 [imm]
  31. * opcode dest [addr]
  32. * ccode [dest] addr
  33. */
  34. decoded_instr *decode(int the_instr);
  35. int carry(decoded_instr *instr);
  36. int sign(decoded_instr *instr);
  37. int indirect_dest(decoded_instr *instr);
  38. int indirect_src2(decoded_instr *instr);
  39. void print(FILE* file, decoded_instr *instr);
  40. void normalizeValues(decoded_instr *instr);
  41. /*
  42. Formats
  43. 00 opcode dest src1 [src2] [func]
  44. 0000 ADD
  45. 0001 SUB
  46. 0010 ANDL
  47. 0011 ORL
  48. 0100 XORL
  49. 0101 ANDB
  50. 0110 ORB
  51. 0111 XORB
  52. 1000 MUL
  53. 1001 DIV
  54. 1010 SHL
  55. 1011 SHR
  56. 1100 ROTL
  57. 1101 ROTR
  58. 1110 NEG
  59. 1111 (SPCL, used for extensions)
  60. func bits
  61. 0 add carry
  62. 1 signed/unsigned
  63. 2 indirect addressing dest
  64. 3 indirect addressing src2
  65. 4
  66. 5
  67. 6
  68. 7
  69. 8
  70. 9
  71. 10
  72. 11
  73. 01 opcode dest src1 [imm]
  74. 0000 ADDI
  75. 0001 SUBI
  76. 0010 ANDLI
  77. 0011 ORLI
  78. 0100 XORLI
  79. 0101 ANDBI
  80. 0110 ORBI
  81. 0111 XORBI
  82. 1000 MULI
  83. 1001 DIVI
  84. 1010 SHLI
  85. 1011 SHRI
  86. 1100 ROTLI
  87. 1101 ROTRI
  88. 1110 NOTL
  89. 1111 NOTB
  90. 10 opcode [dest] [addr]
  91. 0000 NOP
  92. 0001 MOVA
  93. 0010 JSR
  94. 0011 RET
  95. 0100 LOAD
  96. 0101 STORE
  97. 0110 HALT
  98. 0111 SEQ
  99. 1000 SGE
  100. 1001 SGT
  101. 1010 SLE
  102. 1011 SLT
  103. 1100 SNE
  104. 1101 READ
  105. 1110 WRITE
  106. 1111
  107. 11 ccode [dest] addr
  108. Branch to:
  109. 0000 T
  110. 0001 F
  111. 0010 HI
  112. 0011 LS
  113. 0100 CC
  114. 0101 CS
  115. 0110 NE
  116. 0111 EQ
  117. 1000 VC
  118. 1001 VS
  119. 1010 PL
  120. 1011 MI
  121. 1100 GE
  122. 1101 LT
  123. 1110 GT
  124. 1111 LE
  125. */
  126. #endif /* _DECODE_H */