RudyAngus 发表于 2011-5-18 22:16:22

求指点。。。用Verilog编了个栈。。。但是。。。

本帖最后由 RudyAngus 于 2011-5-18 22:21 编辑

如题,用Verilog编了个栈,但模拟的时候始终不能实现。
代码如下:
module stk(clk,khr,push,pop,clr,clx,done,stkup);

input khr;
input clk;
input push;
input pop;
input clr;
input clx;
output done;
output stkup;


reg done;
reg stkup;
reg stk ;




initial done = 1'b0;
initial stkup = 16'h0000;

always @(posedge clk)
begin

if(push==1) begin
                stk<=khr;
                stk<=stk;
                stk<=stk;
                stk<=stk;
                end
else if(pop==1)
                begin
                stkup<=stk;
                stk<=stk;
                stk<=stk;
                stk<=stk;
                end
else if(clr==1) begin
                stk<=16'b0;
                stk<=16'b0;
                stk<=16'b0;
                stk<=16'b0;
                end
               
end
endmodule


Test bench如下:

module tb_stk;

        // Inputs
        reg clk;
        reg khr;
        reg push;
        reg pop;
        reg clr;
        reg clx;

        // Outputs
        wire done;
        wire stkup;
   wire stk ;

        // 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始终不能往里面输入数值。。。求各位高人指点
页: [1]
查看完整版本: 求指点。。。用Verilog编了个栈。。。但是。。。