ControlUnit.v 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * Control Unit
  3. */
  4. module ControlUnit(
  5. input [3:0] instrOP,
  6. input he,
  7. output reg alu_use_const,
  8. output reg push, pop,
  9. output reg dreg_we,
  10. output reg mem_write, mem_read,
  11. output reg jumpc, jumpr, branch, halt, reti,
  12. output reg getIntID, getPC
  13. );
  14. // Instruction Opcodes
  15. localparam
  16. OP_HALT = 4'b1111,
  17. OP_READ = 4'b1110,
  18. OP_WRITE = 4'b1101,
  19. OP_INTID = 4'b1100,
  20. OP_PUSH = 4'b1011,
  21. OP_POP = 4'b1010,
  22. OP_JUMP = 4'b1001,
  23. OP_JUMPR = 4'b1000,
  24. OP_UNDEF1 = 4'b0111, // undefined
  25. OP_BRANCH = 4'b0110,
  26. OP_SAVPC = 4'b0101,
  27. OP_RETI = 4'b0100,
  28. OP_UNDEF2 = 4'b0011, // undefined
  29. OP_UNDEF3 = 4'b0010, // undefined
  30. OP_ARITHC = 4'b0001,
  31. OP_ARITH = 4'b0000;
  32. always @(*) begin
  33. // default
  34. alu_use_const <= 1'b0;
  35. push <= 1'b0;
  36. pop <= 1'b0;
  37. dreg_we <= 1'b0;
  38. mem_write <= 1'b0;
  39. mem_read <= 1'b0;
  40. jumpc <= 1'b0;
  41. jumpr <= 1'b0;
  42. getIntID <= 1'b0;
  43. getPC <= 1'b0;
  44. branch <= 1'b0;
  45. halt <= 1'b0;
  46. reti <= 1'b0;
  47. case (instrOP)
  48. OP_HALT:
  49. begin
  50. halt <= 1'b1;
  51. end
  52. OP_READ:
  53. begin
  54. mem_read <= 1'b1;
  55. dreg_we <= 1'b1;
  56. end
  57. OP_WRITE:
  58. begin
  59. mem_write <= 1'b1;
  60. end
  61. OP_INTID: // write interrupt ID to dreg
  62. begin
  63. getIntID <= 1'b1;
  64. dreg_we <= 1'b1;
  65. end
  66. OP_PUSH: // push reg to stack
  67. begin
  68. push <= 1'b1;
  69. end
  70. OP_POP: // pop stack tot reg
  71. begin
  72. dreg_we <= 1'b1;
  73. pop <= 1'b1;
  74. end
  75. OP_JUMP:
  76. begin
  77. jumpc <= 1'b1;
  78. end
  79. OP_JUMPR:
  80. begin
  81. jumpr <= 1'b1;
  82. end
  83. OP_BRANCH:
  84. begin
  85. branch <= 1'b1;
  86. end
  87. OP_SAVPC: // write PC to dreg
  88. begin
  89. getPC <= 1'b1;
  90. dreg_we <= 1'b1;
  91. end
  92. OP_RETI:
  93. begin
  94. reti <= 1'b1;
  95. end
  96. OP_ARITH:
  97. begin
  98. dreg_we <= 1'b1;
  99. end
  100. OP_ARITHC:
  101. begin
  102. alu_use_const <= 1'b1;
  103. dreg_we <= 1'b1;
  104. end
  105. endcase
  106. end
  107. endmodule