HDLBits (19) — 更多扩展
2022-01-25 01:06 作者:僚机Wingplane | 我要投稿
本题链接:
https://hdlbits.01xz.net/wiki/Vector5
给定五个 1 位信号(a、b、c、d 和 e),25 位输出向量是计算两组 25 位输出向量按位成对比较的结果。 如果被比较的两位相等,则输出应为 1。
out[24] = ~a ^ a; // a == a, so out[24] is always 1.
out[23] = ~a ^ b;
out[22] = ~a ^ c;
...
out[ 1] = ~e ^ d;
out[ 0] = ~e ^ e;

如图所示,使用扩展运算符和拼接运算符可以更轻松地完成此操作。
上面的向量是重复 5 次同一个输入信号后按次序拼接,下面的向量是按次序拼接输入信号后重复5次

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

答案
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
module top_module (
input a, b, c, d, e,
output [24:0] out
);
wire [24:0] top, bottom;
assign top = { {5{a}}, {5{b}}, {5{c}}, {5{d}}, {5{e}} };
assign bottom = {5{a,b,c,d,e}};
assign out = ~top ^ bottom;
endmodule