集成电路技术分享

 找回密码
 我要注册

QQ登录

只需一步,快速开始

搜索
查看: 1636|回复: 0

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

[复制链接]
RudyAngus 发表于 2011-5-18 22:16:22 | 显示全部楼层 |阅读模式
本帖最后由 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
您需要登录后才可以回帖 登录 | 我要注册

本版积分规则

关闭

站长推荐上一条 /1 下一条

QQ|小黑屋|手机版|Archiver|fpga论坛|fpga设计论坛 ( 京ICP备20003123号-1 )

GMT+8, 2025-6-23 05:58 , Processed in 0.066165 second(s), 21 queries .

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表