HDLBITS笔记13:构建100输入与门、或门、异或门的组合电路

题目1:构建具有 100 个输入的组合电路,采用[99:0]。

有 3 个输出:

  • out_and:100 输入 AND 门的输出。
  • out_or:100 输入 OR 门的输出。
  • out_xor:100输入异或门的输出。

采用数据流建模的方式,代码如下:

module top_module( 
    input [99:0] in,
    output out_and,
    output out_or,
    output out_xor 
);
    assign out_and = ∈
    assign out_or = |in;
    assign out_xor = ^in;
endmodule

题目2:给定一个 100 位输入向量 [99:0],反转其位顺序(vector100r)。

使用行为级建模方式及for循环实现。

module top_module( 
    input [99:0] in,
    output [99:0] out
);
    always@(in)
        begin
            integer i;
            for(i=0;i<100;i=i+1)
                out[99-i] = in[i];
        end
        
endmodule

题目3:计算255位输入向量中1的个数。

使用行为级建模方式及for循环实现:

module top_module( 
    input [254:0] in,
    output [7:0] out );
integer count;
    always@(in)
        begin
            integer i ;
            count = 0;
            for(i=0;i<255;i=i+1)
                if(in[i] == 1)
                count = count+1;
            else
                count = count;
        end
    assign out = count;
endmodule

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值