HDLBits练习答案(持续更新)

1.Getting Started

2. Verilog Language

2.3 Modules:Hierarchy

2.3.5 Modules and vertors

module top_module ( 
    input clk, 
    input [7:0] d, 
    input [1:0] sel, 
    output [7:0] q 
);
    wire [7:0]	q1,q2,q3,qout;
    
    my_dff8 U1(clk, d, q1);
    my_dff8 U2(clk, q1, q2);
    my_dff8 U3(clk, q2, q3);
    
    always	@(*)
        begin
            case(sel)
                2'b00:	qout<=d;
                2'b01:	qout<=q1;
                2'b10:	qout<=q2;
                2'b11:	qout<=q3;   
            endcase
        end
    assign q=qout;
endmodule

2.3.6 Adder 1

方法1:直接使用变量进行访问,处理方法是将相应的数据按照Module定义的顺序进行调用,参数位置不可以错

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire [15:0]	suml,sumh;
    wire cinl,coutl,couth;
    
    assign cinl=0;
    add16 U1(a[15:0], b[15:0], cinl, suml, coutl);
    add16 U2(a[31:16], b[31:16], coutl, sumh, couth);
    assign sum={
   sumh, suml};    
endmodule

方法2:使用点变量的方式,好处就是参数位置可以随意调整。

module top_module(
    input [31:0] a,
    input [31:0] b,
    output [31:0] sum
);
    wire [15:0]	suml,sumh;
    wire cinl,coutl,couth;
    
    assign cinl=0;
    add16 U1(.b(b[15:0]), .cin(cinl), .sum(suml), .cout(coutl),.a(a[15:0]) );
    add16 U2(.a(a[31:16]
  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值