Advertisement
Guest User

Untitled

a guest
May 21st, 2019
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.40 KB | None | 0 0
  1. `timescale 1ns / 1ps
  2. //////////////////////////////////////////////////////////////////////////////////
  3. // Company: ETH Zurich
  4. // Engineer: Frank K. Gurkaynak
  5. //
  6. // Create Date: 12:51:05 03/17/2011
  7. // Design Name: MIPS processor
  8. // Module Name: ALU
  9. // Project Name: Digital Circuits Lab Exercise
  10. // Target Devices:
  11. // Tool versions:
  12. // Description: This is one possible solution to the
  13. // ALU description from Lab5a
  14. // Dependencies:
  15. //
  16. // Revision:
  17. // Revision 0.01 - File Created
  18. // Additional Comments:
  19. //
  20. //////////////////////////////////////////////////////////////////////////////////
  21. module ALU(
  22. input [31:0] a,
  23. input [31:0] b,
  24. // input [3:0] aluop,
  25. input [5:0] aluop,
  26. input [4:0] ShAmt,
  27. input clk,
  28. input reset,
  29. output [31:0] result,
  30. output zero
  31. );
  32.  
  33. wire [31:0] logicout; // output of the logic block
  34. wire [31:0] addout; // adder subtractor out
  35. wire [31:0] arithout; // output after alt
  36. wire [31:0] n_b; // inverted b
  37. wire [31:0] sel_b; // select b or n_b;
  38. wire [31:0] slt; // output of the slt extension
  39. wire [31:0] srl;
  40. reg [31:0] lo;
  41.  
  42. wire [1:0] logicsel; // lower two bits of aluop;
  43.  
  44. // logic select
  45. assign logicsel = aluop[1:0];
  46. assign logicout = (logicsel == 2'b00) ? a & b :
  47. (logicsel == 2'b01) ? a | b :
  48. (logicsel == 2'b10) ? a ^ b :
  49. ~(a | b);
  50.  
  51. // adder subtractor
  52. assign n_b = ~b ; // invert b
  53. assign sel_b = (aluop[1])? n_b : b ;
  54. assign addout = a + sel_b + aluop[1];
  55.  
  56. // set less than operator
  57. assign slt = {31'b0,addout[31]};
  58.  
  59. // arith out
  60. assign arithout = (aluop[3]) ? slt : addout;
  61.  
  62. // new: srl, multu, mflo
  63. assign srl = b >> ShAmt;
  64.  
  65. // mflo logic
  66. always @(posedge clk, posedge reset)
  67. begin
  68. if (aluop == 6'b011001) begin
  69. lo = a * b;
  70. end
  71.  
  72. if (reset == 1'b1) begin
  73. lo = 0;
  74. end
  75.  
  76. end
  77.  
  78. // final out
  79. assign result = (aluop == 6'b000010) ? srl : (aluop == 6'b010010)? lo : (aluop[2]) ? logicout : arithout;
  80.  
  81.  
  82.  
  83.  
  84. // assign result = (aluop == 6'b000010) ? srl : result;
  85. // assign result = (aluop == 6'b010010) ? lo : result; // outputs the lo value if we move from lo.
  86.  
  87.  
  88. // the zero
  89. assign zero = (result == 32'b0) ? 1: 0;
  90.  
  91. endmodule
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement