在verilog中将线向量转换为整数
Casting wire vector to integer in verilog
在这样的例子中
function module(
input [3:0] in
output out);
for(integer i = in; i < in+10; i += 1) begin
// do stuff
end
endfunction
如何将 in
转换为 i
?
据我了解,整数是一个 32 位位向量,用 2 的补码解释。
那么verilog是否用28{in[3]}
填充位向量?
来自 LRM
If needed, extend the size of the right-hand side, performing sign extension if, and only if, the type of the right-hand side is signed.
因此,在您的情况下,i
将填充为“0”,而不是 in[3],因为 in
未签名。
要进行符号扩展,您需要输入符号:input signed [3:0] in;
在这样的例子中
function module(
input [3:0] in
output out);
for(integer i = in; i < in+10; i += 1) begin
// do stuff
end
endfunction
如何将 in
转换为 i
?
据我了解,整数是一个 32 位位向量,用 2 的补码解释。
那么verilog是否用28{in[3]}
填充位向量?
来自 LRM
If needed, extend the size of the right-hand side, performing sign extension if, and only if, the type of the right-hand side is signed.
因此,在您的情况下,i
将填充为“0”,而不是 in[3],因为 in
未签名。
要进行符号扩展,您需要输入符号:input signed [3:0] in;