HDL bits 做题日常 13/11

文章讲述了如何在Verilog设计中实例化my_dff模块创建D型移位寄存器,以及使用选择器模块和加法器模块进行数据处理,涉及模块连接和信号传递的方法。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.You are given a module my_dff with two inputs and one output (that implements a D flip-flop). Instantiate three of them, then chain them together to make a shift register of length 3. The clk port needs to be connected to all instances.

我:

module top_module ( input clk, input d, output q );
    wire dff12,dff23;
    my_dff instance1(.clk(clk), .d(d), .q(dff12));
    my_dff instance2(.clk(clk), .d(dff12), .q(dff23));
    my_dff instance3(.clk(clk), .d(dff23), .q(q));

endmodule

note:这题错了很久。

官网:

module top_module (
    input clk,
    input d,
    output q
);

    wire a, b;    // Create two wires. I called them a and b.

    // Create three instances of my_dff, with three different instance names (d1, d2, and d3).
    // Connect ports by position: ( input clk, input d, output q)
    my_dff d1 ( clk, d, a );
    my_dff d2 ( clk, a, b );
    my_dff d3 ( clk, b, q );

endmodule

2.modules and vectors

module top_module ( 
    input clk, 
    input [7:0] d, 
    input [1:0] sel, 
    output [7:0] q 
);
    wire [7:0] w1;
    wire [7:0] w2;
    wire [7:0] w3;
    wire [7:0] w4;
    wire [1:0] w5;
    my_dff8 instance1(.clk(clk), .d(d), .q(w1));
    my_dff8 instance2(.clk(clk), .d(w1), .q(w2));
    my_dff8 instance3(.clk(clk), .d(w2), .q(w3));
    always@ (sel or d or w1 or w2 or w3)
        case(sel)
            2'b00:q<=d;
            2'b01:q<=w1;
            2'b10:q<=w2;
            2'b11:q<=w3;
        endcase
        
    
endmodule

刚开始想写一个数据选择器的模块,然后再实例化,所以用了好久。。。。

3.module-adder1

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire w1;
    wire [15:0]w2;
    wire w3;
    wire [15:0]w4;
    assign w3=0;
    add16 instance1(.a(a[15:0]), .b(b[15:0]), .cout(w1), .sum(w2), .cin(w3));
    add16 instance2(.a(a[31:16]), .b(b[31:16]), .cin(w1), .sum(w4), .cout());
    assign sum={w4,w2};

endmodule

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值