Advertisement
Guest User

Untitled

a guest
Feb 20th, 2020
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.95 KB | None | 0 0
  1. // mips_decode: a decoder for MIPS arithmetic instructions
  2. //
  3. // alu_op (output) - control signal to be sent to the ALU
  4. // writeenable (output) - should a new value be captured by the register file
  5. // rd_src (output) - should the destination register be rd (0) or rt (1)
  6. // alu_src2 (output) - should the 2nd ALU source be a register (0) or an immediate (1)
  7. // except (output) - set to 1 when we don't recognize an opdcode & funct combination
  8. // control_type (output) - 00 = fallthrough, 01 = branch_target, 10 = jump_target, 11 = jump_register
  9. // mem_read (output) - the register value written is coming from the memory
  10. // word_we (output) - we're writing a word's worth of data
  11. // byte_we (output) - we're only writing a byte's worth of data
  12. // byte_load (output) - we're doing a byte load
  13. // slt (output) - the instruction is an slt
  14. // lui (output) - the instruction is a lui
  15. // addm (output) - the instruction is an addm
  16. // opcode (input) - the opcode field from the instruction
  17. // funct (input) - the function field from the instruction
  18. // zero (input) - from the ALU
  19. //
  20.  
  21. module mips_decode(alu_op, writeenable, rd_src, alu_src2, except, control_type,
  22. mem_read, word_we, byte_we, byte_load, slt, lui, addm,
  23. opcode, funct, zero);
  24. output [2:0] alu_op;
  25. output [1:0] alu_src2;
  26. output writeenable, rd_src, except;
  27. output [1:0] control_type;
  28. output mem_read, word_we, byte_we, byte_load, slt, lui, addm;
  29. input [5:0] opcode, funct;
  30. input zero;
  31.  
  32. output rd_src, writeenable, except;
  33. output [1:0] alu_src2;
  34. output [2:0] alu_op;
  35. input [5:0] opcode, funct;
  36.  
  37. wire w_add = opcode == `OP_OTHER0 && funct ==`OP0_ADD;
  38. wire w_addu = opcode == `OP_OTHER0 && funct ==`OP0_ADDU;
  39. wire w_sub = opcode == `OP_OTHER0 && funct ==`OP0_SUB;
  40. wire w_and = opcode == `OP_OTHER0 && funct ==`OP0_AND;
  41. wire w_or = opcode == `OP_OTHER0 && funct ==`OP0_OR;
  42. wire w_nor = opcode == `OP_OTHER0 && funct ==`OP0_NOR;
  43. wire w_xor = opcode == `OP_OTHER0 && funct ==`OP0_XOR;
  44.  
  45. wire w_addi = opcode == `OP_ADDI;
  46. wire w_addiu = opcode == `OP_ADDIU;
  47. wire w_andi = opcode == `OP_ANDI;
  48. wire w_ori = opcode == `OP_ORI;
  49. wire w_xori = opcode == `OP_XORI;
  50.  
  51. wire w_beq = (opcode == `OP_BEQ);
  52. wire w_bne = (opcode == `OP_BNE);
  53. wire w_j = (opcode == `OP_J);
  54. wire w_jr = (opcode == `OP_OTHER0) & (funct == `OP0_JR);
  55. wire w_lui = (opcode == `OP_LUI);
  56. wire w_slt = (opcode == `OP_OTHER0) & (funct == `OP0_SLT);
  57. wire w_lw = (opcode == `OP_LW);
  58. wire w_lbu = (opcode == `OP_LBU);
  59. wire w_sw = (opcode == `OP_SW);
  60. wire w_sb = (opcode == `OP_SB);
  61. wire w_addm = (opcode == `OP_OTHER0) & (funct == `OP0_ADDM);
  62.  
  63. assign rd_src = (w_addiu | w_addi | w_andi | w_ori | w_xori | w_lui | w_lw | w_lbu | w_sw | w_sb);
  64. assign writeenable = ~(w_beq | w_bne | w_j | w_jr | w_sw | w_sb | except)//
  65. assign except = ~(w_add | w_addu | w_addiu | w_addi | w_sub | w_and | w_andi | w_or | w_ori | w_nor | w_xor | w_xori | w_beq | w_bne | w_j | w_jr | w_lui | w_slt | w_lw | w_lbu | w_sw | w_sb | w_addm);
  66.  
  67.  
  68. assign alu_op[0] = (w_sub | w_or | w_ori | w_xor | w_xori | w_beq | w_bne | w_slt);
  69. assign alu_op[1] = (w_add | w_addi | w_sub | w_nor | w_xor | w_xori | w_beq | w_bne | w_slt | w_lw | w_lbu | w_sw | w_sb | w_addm);
  70. assign alu_op[2] = (w_and | w_andi | w_or | w_ori | w_nor | w_xor | w_xori);
  71.  
  72.  
  73. assign control_type[0] = (w_beq & zero) | (w_bne & !zero) | w_jr;
  74. assign control_type[1] = w_j | w_jr;
  75. assign mem_read = w_lw | w_lbu;
  76. assign word_we = w_sw;
  77. assign byte_we = w_sb;
  78. assign byte_load = w_lbu;
  79. assign lui = w_lui;
  80. assign slt = w_slt;
  81. assign addm = w_addm;
  82.  
  83.  
  84.  
  85. assign alu_src2[0] = (w_addi | w_addiu);
  86. assign alu_src2[1] = (w_andi | w_ori | w_xori);
  87.  
  88. endmodule // mips_decode
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement