具体Verilog 代码如下:
module fifo
#(
parameter B = 8,
)
(
input wire clk,reset,
input rd,wr,
input wire [B-1:0] w_data,
output wire empty,full,
output wire [B-1:0] r_data
);
//signal declaration
reg [B-1:0] array_reg [2**W-1:0]; //register array
reg [W-1:0] w_ptr_reg,w_ptr_next,w_ptr_succ;
reg [W-1:0] r_ptr_reg,r_ptr_next,r_ptr_succ;
reg full_reg, empty_reg,full_next,empty_next;
wire wr_en;
//body
//register file write operation
always @(posedge clk)
assign wr_en = wr & ~full_reg;
//fifo control logic
//register for read and write pointers
always @(posedge clk, posedge reset)
//next-state logic for read and
write pointers
always @*
begin
//successive pointer valus
w_ptr_succ = w_ptr_reg + 1;
r_ptr_succ = r_ptr_reg + 1;
//default : keep old values
w_ptr_next = w_ptr_reg;
r_ptr_next = r_ptr_reg;
full_next = full_reg;
empty_next = empty_reg;
case({wr,rd})
//2;b00 : no op
2'b01:
2'b10:
2'b11:
endcase
end
//output
assign full = full_reg;
assign empty = empty_reg;
endmodule