|
本帖最后由 RudyAngus 于 2011-5-18 22:21 编辑
如题,用Verilog编了个栈,但模拟的时候始终不能实现。
代码如下:
module stk(clk,khr,push,pop,clr,clx,done,stkup);
input [15:0] khr;
input clk;
input push;
input pop;
input clr;
input clx;
output done;
output stkup;
reg done;
reg [15:0]stkup;
reg [15:0] stk [3:0];
initial done = 1'b0;
initial stkup = 16'h0000;
always @(posedge clk)
begin
if(push==1) begin
stk[0]<=khr;
stk[1]<=stk[0];
stk[2]<=stk[1];
stk[3]<=stk[2];
end
else if(pop==1)
begin
stkup<=stk[0];
stk[0]<=stk[1];
stk[1]<=stk[2];
stk[2]<=stk[3];
end
else if(clr==1) begin
stk[0]<=16'b0;
stk[1]<=16'b0;
stk[2]<=16'b0;
stk[3]<=16'b0;
end
end
endmodule
Test bench如下:
module tb_stk;
// Inputs
reg clk;
reg [15:0] khr;
reg push;
reg pop;
reg clr;
reg clx;
// Outputs
wire done;
wire [15:0] stkup;
wire [15:0] stk [3:0];
// Instantiate the Unit Under Test (UUT)
stk stack(clk,khr,push,pop,clr,clx,done,stkup);
initial begin
// Initialize Inputs
clk = 0;
push =0;
forever #1clk = ~clk;
end
initial begin
#4 khr=16'h0000;
#4 begin
push =1'b1 ;
khr=16'h0001;
end
// Add stimulus here
end
endmodule
最后模拟结果如图
主要问题是不知道为什么reg stk[3:0]始终不能往里面输入数值。。。求各位高人指点 |
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有账号?我要注册
x
|