【无标题】

//1 .
module top_module ( 
    input wire [2:0] vec,
    output wire [2:0] outv,
    output wire o2,
    output wire o1,
    output wire o0  ); // Module body starts after module declaration
	assign outv = vec;
    assign o2 = vec[2];
    assign o1 = vec[1];
    assign o0 = vec[0];
endmodule
//2 .Build a combinational circuit that splits an input half-word (16 bits, [15:0] ) into lower [7:0] and upper [15:8] bytes.
module top_module( 
    input wire [15:0] in,
    output wire [7:0] out_hi,
    output wire [7:0] out_lo );
    assign out_hi = in[15:8];
    assign out_lo = in[7:0];
endmodule
//3 .A32-bit vector can be viewed as containing 4 bytes (bits [31:24], [23:16], etc.). Build a circuit that will reverse the byte ordering of the 4-byte word.
//AaaaaaaaBbbbbbbbCcccccccDddddddd => DdddddddCcccccccBbbbbbbbAaaaaaaa
module top_module( 
    input [31:0] in,
    output [31:0] out );//

    // assign out[31:24] = ...;
    assign out[31:24] = in[7:0];
    assign out[23:16] = in[15:8];
    assign out[15:8]  = in[23:16];
    assign out[7:0]   = in[31:24];
endmodule
//4 .构建一个具有两个 3 位输入的电路,用于计算两个向量的按位 OR、两个向量的逻辑 OR 以及两个向量的逆 (NOT)。将b的倒数放在上半部分(即位 [5:3]),并将a的倒数放在下半部分。
module top_module( 
    input [2:0] a,
    input [2:0] b,
    output [2:0] out_or_bitwise,
    output out_or_logical,
    output [5:0] out_not
);
assign out_or_bitwise = a | b;
    assign out_or_logical = a || b;
    assign out_not[5:3] = ~b;
    assign out_not[2:0] = ~a;
endmodule
//5  .构建具有四个输入的组合电路,in[3:0]。
//有 3 个输出:按位
//out_and:4 输入 AND 门的输出。
//out_or:4 输入 OR 门的输出。
//out_xor:4输入异或门的输出。
module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
	assign out_and = ∈
    assign out_or = |in;
    assign out_xor = ^in;
endmodule

//6  .串联运算符 {a,b,c} 用于通过将向量的较小部分连接在一起来创建较大的向量。
//给定多个输入向量,将它们连接在一起,然后将它们拆分为多个输出向量。
//有六个 5 位输入向量:a、b、c、d、e 和 f,总共 30 位输入。
//有四个 8 位输出向量:w、x、y 和 z,用于 32 位输出。输出应是输入向量的串联,后跟两个 1 位:
module top_module (
    input [4:0] a, b, c, d, e, f,
    output [7:0] w, x, y, z );//

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

endmodule
//7  .给定一个 8 位输入向量 [7:0],反转其位顺序。
module top_module( 
    input [7:0] in,
    output [7:0] out
);
    assign  out[7:0] ={in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]}; 
endmodule
//8  .复制运算符允许重复向量并将它们连接在一起:{num{vector}}
//构建一个将 8 位数字符号扩展到 32 位的电路。这需要24个符号位副本(即复制位[7]24次)的串联,后跟8位数字本身。
    module top_module (
        input [7:0] in,
        output [31:0] out );//

        assign out = { {24{in[7]}},in[7:0]};

    endmodule
//9  .给定五个 1 位信号(a、b、c、d 和 e),计算 25 位输出矢量中的所有 25 个成对单位比较。如果要比较的两位相等,则输出应为 1。
//顶部矢量是每个输入的 5 次重复的串联
//底部矢量是 5 个输入串联的 5 次重复
module top_module (
    input a, b, c, d, e,
    output [24:0] out );//


    assign out = ~{{5{a}},{5{b}},{5{c}},{5{d}},{5{e}}} ^ {5{a,b,c,d,e}};

endmodule











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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值