Skip to content

Instantly share code, notes, and snippets.

@oskimura
Created December 25, 2016 06:32
Show Gist options
  • Save oskimura/c045437389ef5dd6e90bc94afcceacbe to your computer and use it in GitHub Desktop.
Save oskimura/c045437389ef5dd6e90bc94afcceacbe to your computer and use it in GitHub Desktop.
`include "regfile.h"
module regfile(
input wire clk,
input wire reset_,
input wire [`AddrBus] addr,
input wire [`DATABus] d_in,
input wire we_,
output wire [`DATABus] d_out
);
reg [`DataBus] ff[`DATA_D-1:0];
integer i;
assign d_out = ff[addr];
always @(posedge clk or negedge reset_) begin
if (reset_==`ENABLE) begin
for (i=0;i < `DATA_D; i=i+1) begin
ff[i] <= #1 {`DATA_W{1'b0}};
end
end else begin
if (we_ == `ENABLE) begin
ff[addr] <= #1 d_in;
end
end
end
endmodule
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment