HDLBits--vector

Gates4

规约运算,或者拆开按位与,或,异或

module top_module( 
    input [3:0] in,
    output out_and,
    output out_or,
    output out_xor
);
    assign out_and = ∈	#规约运算
    out_or = |in;
    out_xnor = ^in;
endmodule

Vector3

比较蠢的方法,自己计算;

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

使用并位运算

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

Vectorr

最原始的方法

module top_module( 
    input [7:0] in,
    output [7:0] out
);
    assign out = {in[0],in[1],in[2],in[3],in[4],in[5],in[6],in[7]};

endmodule

Vector4

{5{1’b1}} 复制运算符,可以理解为两个并位运算符的组合,但是这才是一个正确的复制操作

module top_module (
    input [7:0] in,
    output [31:0] out );
    assign out = {{24{in[7]}},in}; #切忌out = {24{in[7]},in}
endmodule

Vector5

在这里插入图片描述
其实按照上面这个图片来对这个并位就可以

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、付费专栏及课程。

余额充值