补发 FPGA学习日记(5) 全加器

模块化  调用半加器模块  在全加器模块中对两个半加器分别进行实例化 

 用两个半加器实现全加器 ,用或门连接两个进位信号

module full_addr

module full_addr
(
    input  wire in1,
    input  wire in2,
    input  wire cin,
    output wire sum,
    output wire count
);

wire h0_sum;
wire h0_count;
wire h1_count;


half_addr half_addr_inst0
(
    .in1(in1),
    .in2(in2),
    .sum(h0_sum),
    .count(h0_count)
);

half_addr half_addr_inst1
(
    .in1(h0_sum),
    .in2(cin),
    .sum(sum),
    .count(h1_count)
);

assign count=(h0_count | h1_count)

endmodule

module tb_full_addr

module tb_full_addr();

reg in1;
reg in2;
reg cin;
wire sum;
wire count;

initial
    begin
        in1 <= 1'b0;
        in2 <= 1'b0;
        cin <= 1'b0;
    end

initial 
    begin
        $timeformat(-9,0,"ns",6);
        $monitor("time %t:in1 = %b,in2 = %b, cin = %b, sum = %b,count = %b",$time,in1,in2,cin,sum,count)

always #10 in1 <= {$random}%2;
always #10 in2 <= {$random}%2;
always #10 cin <= {$random}%2;

full_addr full_addr_inst
(
    .in1(in1),
    .in2(in2),
    .cin(cin),
    .sum(sum),
    .count(count)
);

endmodule

 

打印信息

 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值