`define
DEPTH 9'h4
//511 =1FFh
`define
DEPTHBIT 3'd2
//0~8 9位 511
module
fifo_MOD(
Data,
Clock,
WrEn,
RdEn,
Reset,
Q,
Empty,
Full
);
input [127:0] Data/* synthesis syn_ramstyle. = "block_ram" */;
input Clock;
input WrEn;
input RdEn;
input Reset;
output reg [127:0] Q/* synthesis syn_ramstyle. = "block_ram" */;
output Empty;
output Full;
wire[`DEPTHBIT:0] Count;
reg[`DEPTHBIT:0] DeCount;
reg directory;
reg[127:0]
ram[`DEPTH-1:0]/* synthesis syn_ramstyle. = "block_ram" */;
reg[`DEPTHBIT-1:0] InputIndex;
reg[`DEPTHBIT-1:0] OutputIndex;
always@ ( posedge Clock)
if(!Reset)
begin
InputIndex<=0;
OutputIndex<=0;
directory<=0;
//Count<=0;
DeCount<= `DEPTH;
end
else
begin
case ({(WrEn&~Full),(RdEn&~Empty)})
2'b10:
begin
ram[InputIndex]<=Data;
InputIndex<=InputIndex+1;
DeCount<=DeCount-1 ;
end
2'b01:
begin
Q<=ram[OutputIndex];
OutputIndex<=OutputIndex+1;
DeCount<=DeCount+1;
end
2'b11:
begin
ram[InputIndex]<=Data;
Q<=ram[OutputIndex];
InputIndex<=InputIndex+1;
OutputIndex<=OutputIndex+1;
end
default:
begin
Q<={127{1'b0}};
end
endcase
end
assign Full=(DeCount==0);
assign Empty=(DeCount==`DEPTH);
assign Count=(`DEPTH-DeCount);
endmodule
上面是我写的一个先进先出 模块,这里要注意的是 阻塞赋值与非阻塞赋值在一个模块中的执行顺序
经过观察波形可以看到
模块先执行的是非阻塞赋值后进行的阻塞赋值即先计算完DeCount;得到最新的Decount值在计算的Count值