第五节记录

//1. 三元运算符的使用
module top_module (
    input [7:0] a, b, c, d,
    output [7:0] min);//
    wire [7:0]e,f;
    assign e = (a<b)?a:b;
    assign f = (c<d)?c:d;
    assign min = (e<f)?e:f;
    // assign intermediate_result1 = compare? true: false;

endmodule
//2.对一个向量的所有位进行操作,比如(a[0] & a[1] & a[2] & a[3] ... ),
module top_module (
    input [7:0] in,
    output parity); 
    assign parity = ^in[7:0];
endmodule
//3.构建具有 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 
);
    always@(*)begin
        out_and = &in[99:0];
        out_or =  |in[99:0];
        out_xor = ^in[99:0];
    end
endmodule
//4.给定一个 100 位输入向量 [99:0],反转其位顺序。
module top_module( 
    input [99:0] in,
    output [99:0] out
);
    int i;
    always@(*)begin
        for(i=0;i<100;i=i+1)
            out[i] = in[99-i];
    end
endmodule
//5.人口计数"电路计算输入向量中"1"的数量。为 255 位输入向量构建人口计数电路
module top_module( 
    input [254:0] in,
    output [7:0] out );
    int i;
    always@(*)begin
        out = 8'b0;
        for(i = 0;i<255;i=i+1)begin
            if(in[i] == 1) out = out + 1'b1;
            else out = out;
        end
    end
endmodule
//6.
module top_module( 
    input [99:0] a, b,
    input cin,
    output [99:0] cout,
    output [99:0] sum );
    
    generate
        genvar i;
        for(i = 0; i <= 99; i = i + 1)begin:adder
        	if(i == 0)begin
            	assign {cout[0], sum[0]} = a[0] + b[0] + cin;
            end
            else begin
            	assign {cout[i], sum[i]} = a[i] + b[i] + cout[i-1];
            end         
        end
    endgenerate
 
endmodule
//7.
module top_module( 
    input [399:0] a, b,
    input cin,
    output cout,
    output [399:0] sum );
    
    wire[99:0]	cout_1;
    
    generate
        genvar i;
        for(i = 0; i <= 99; i = i + 1)begin:adder
            if(i == 0)begin
                bcd_fadd u_bcd_fadd(
                    .a		(a[3:0]		),
                    .b		(b[3:0]		),
                    .cin	(cin		),
                    .sum	(sum[3:0]	),
                    .cout	(cout_1[0]	)
                );
            end
            else begin
                bcd_fadd ui_bcd_fadd(
                    .a		(a[4 * i + 3: 4 * i]	),
                    .b		(b[4 * i + 3: 4 * i]	),
                    .cin	(cout_1[i - 1]          ),
                    .sum	(sum[4 * i + 3: 4 * i]  ),
                    .cout	(cout_1[i]              )
                );
            end
        end
        assign cout = cout_1[99];
    endgenerate
                    
endmodule

//生成块语句的知识有所欠缺

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值