从vhdl转换为verilog

时间:2018-04-29 05:43:40

标签: verilog vhd

这是来自Testbench的以下VHDL语句;

size_data <= to_unsigned(16,16); // data stream is 16 bits in size

如何将其转换为verilog?

1 个答案:

答案 0 :(得分:0)

Verilog会自动进行转换。

这是一个有符号的值:
wire signed [4:0] I_am_signed; assign I_am_signed = 16;

这是未签名的:
wire [4:0] I_am_unsigned; assign I_am_unsigned = 16;

出错了:
wire signed [3:0] I_am_signed_but_too_small_for_16; assign I_am_signed_but_too_small_for_16= 16;

在最后一种情况下,您不能保证会收到警告或错误,但大多数编译器都会提供警告或错误。然而,在不知道值的情况下不会这样。这可能会发生可怕的错误:
assign I_am_signed_but_too_small_for_16 = I_am_signed;

但这是从签名转换为无签名或反之亦然的安全方式:
assign I_am_unsigned = I_am_signed; assign I_am_signed = I_am_unsigned;