HDLBit刷题记录(一)

该博客探讨了如何使用Verilog进行输入向量的拼接和输出向量的拆分。通过示例模块展示了如何将六个5位输入向量合成为30位,然后分配给四个8位输出向量,并添加两个1位。此外,还介绍了如何通过生成器和位反转操作实现向量转换。最后,讲解了一个XNOR操作的实现,通过重复和异或操作对输入向量进行处理。
摘要由CSDN通过智能技术生成
  • A Bit of Practice

Given several input vectors, concatenate them together then split them up into several output vectors. There are six 5-bit input vectors: a, b, c, d, e, and f, for a total of 30 bits of input. There are four 8-bit output vectors: w, x, y, and z, for 32 bits of output. The output should be a concatenation of the input vectors followed by two 1 bits:

 

module top_module (
    input [4:0] a, b, c, d, e, f,
    output [7:0] w, x, y, z );//
    
    // assign { ... } = { ... };

 assign {w,x,y,z} = {a,b,c,d,e,f,2'b11};
endmodule

  • Vectorr 

module top_module( 
    input [7:0] in,
    output [7:0] out
);
    // assign out[7:0] = in[0:7];  错误示例
    //assign out = {in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]}; //第一种方法
    
    generate
        genvar i;
        for(i = 0; i <= 7;i = i + 1)
            begin:conv
                assign out[i] = in[7-i];
            end
    endgenerate

endmodule

 

  • Vector4

 

module top_module (
    input [7:0] in,
    output [31:0] out );//

    // assign out = { replicate-sign-bit , the-input };
    assign out[31:0] = {{24{in[7]}},in[7:0]};
endmodule
  •  Vector5

 

 XNOR-异或

module top_module (
    input a, b, c, d, e,
    output [24:0] out );//

    // The output is XNOR of two vectors created by 
    // concatenating and replicating the five inputs.
    // assign out = ~{ ... } ^ { ... };
    assign out = ~{{5{a}},{5{b}},{5{c}},{5{d}},{5{e}}} ^ {5{a,b,c,d,e}};

endmodule
  •  Module

module top_module ( input a, input b, output out );

    //mod_a u_mod_a(a,b,out);
    mod_a u_mod_a(
        .in1(a),
        .in2(b),
        .out(out)
    );
endmodule

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值