Verilog:将向量的所有信号异或


13

假设我得到一个wire large_bus[63:0]宽度为64 的向量。如何将各个信号进行XOR运算而不将其全部写入:

assign XOR_value = large_bus[0] ^ large_bus[1] ^ ... ^ large_bus[63]

我对宽度由a指定的向量特别感兴趣localparam

Answers:


14

二进制运算符(如&,|,^等)在verilog中也可以是一元的,这非常方便。它们对操作数执行按位运算,并返回单个位值。参见例如asic-world.com上的归约运算符

reg [63:0] large_bus;

wire xor_value;
assign xor_value = ^large_bus;
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.