I/O Input
(1)Clock Signal(時脈訊號):clk
(2)Write Enable Signal(寫入暫存器訊號):en_write
(3)Address Bus(指定暫存器編號,需要3個5位元):ra1、ra2、wa
(4)Input Data Bus(寫入的資料,需要1個32位元):wd
I/O Output
(1)Output Data Bus(輸出的資料,需要2個32位元):rd1,rd2
module regfile
(
input [4:0] ra1,output [31:0] rd1,
input [4:0] ra2,output [31:0] rd2,
input clk,
input en_write,
input [4:0] wa,input [31:0] wd
);
reg [31:0] registers[31:0];
// 暫存器0永遠輸出0
assign rd1 = (ra1 == 5'b00000) ? 32'h00000000 : registers[ra1];
assign rd2 = (ra2 == 5'b00000) ? 32'h00000000 : registers[ra2];
// 當en_write=1時,執行將wd寫入暫存器的動作
always @(posedge clk)
begin
if ( en_write )
registers[wa] <= wd;
end
endmodule
2 則留言:
請問 4個4 bits 的Register File 該怎麼用 nad not or等邏輯閘表示呢??
you can use chisel scala and intellij to design Risc-V cpu
it's much easier to do the work
張貼留言