1. ALU
module alu (input [31:0] a, b,
input [2:0] alucont,
output reg [31:0] result,
output zero);
wire [31:0] b2;
wire sltu;
wire [32:0] sum;
assign b2 = alucont[2] ? ~b : b;
assign sum[32:0] = a + b2 + alucont[2];
assign sltu = ~sum[32];
always@ (*)
begin
case(alucont[1:0])
2'b00: result <= a & b2;
2'b01: result <= a | b2;
2'b10: result <= sum[31:0];
2'b11: result <= {31'b0, sltu};
endcase
end
assign zero = (result == 32b'0);
endmoudle
2. Control Unit
R-type: opcode, funct 다 읽어야 알 수 있음
I, J-type: opcode만 읽어도 됨
Main Decoder는 opcode 읽어서 signal 만들어서 내보냄
ex) MemToReg, MemWrite, Branch, ALUSrc, RegDst, RegWrite, ALUOp
ALU Decoder는 funct, ALUOp 읽어서 ALUControl(3비트) 만들어서 내보냄
ex) 000, 001, 010, 011(not used), 100, 101, 110, 111
* ALUOp(2비트)
00 add (lw, sw)
01 subtract (beq, bne)
10 R-type이다! funct 봐라!
11 (not used)
ALUOp의 첫 비트가 0이면 fucnt 볼 필요 없음
하지만 첫 비트가 1이라면 funct 읽어야함