HDLBits 刷题之我的代码(全)—(Verification:Writing Testbenches)

19 篇文章 0 订阅

#1

`timescale 1ps/1ps
module top_module ( );

	reg clk;
    initial begin
        clk = 'b0;
        forever 
            #5 clk = ~clk;
    end
 	dut dut1(.clk(clk));
endmodule

#2

`timescale 1ps/1ps
module top_module ( output reg A, output reg B );//

    // generate input patterns here
    initial begin
		A = 0;
        #10
		A = 1;
        #10 
        A = 0;             
    end
    initial begin
        B = 0;
        #15
        B = 1;
        #25  
        B = 0;       
    end
endmodule

#3

`timescale 1ps/1ps
module top_module();
    reg [1:0]in;
    wire out;
	initial begin
        in = 0;
        #10
        in = 1;
        #10
        in = 2;
        #10
        in = 3;      
    end
    andgate u_andgate(
        .in(in),
        .out(out)
	);
endmodule

#4

`timescale 1ps/1ps
module top_module();
    
    reg [2:0]s;
    reg clk;
    reg in;
    wire out;
    initial begin
        clk = 0;
        forever
            #5 clk = ~clk;
    end
	initial begin
        in = 0;
        s = 2;
        #10
        in = 00;
        s = 6;
        #10
        in = 1;
        s = 2;
        #10
        in = 0; 
        s = 7;
        #10
        in = 1;
        s = 0;
        #30
        in = 0;
    end
	q7 u_q7(
        .clk(clk),
        .in(in),
        .s(s),
        .out(out)
	);
endmodule

#5

`timescale 1ps/1ps
module top_module ();
	reg clk;
    reg reset;
    reg t;
    wire q;
    initial begin
        clk = 0;
        forever
            #5 clk = ~clk;
    end
	initial begin
        reset = 1;
        t = 0;
        #10
        reset = 0;
        t = 1;
        #20
        reset = 1;
        t = 0;
    end
	tff  u_tff (
        .clk(clk),
        .reset(reset),
        .t(t),
        .q(q)
	);    
endmodule

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值