0

I have the following VHDL code that defines a constant of particular width.

constant WIDTH : natural := 16
constant X : std_logic_vector(WIDTH - 1 downto 0) := std_logic_vector(to_unsigned(16#0#, WIDTH));

How do I define something like this in SystemVerilog?

I would assume that something like this would correspond to

parameter WIDTH = 16
parameter X = WIDTH'd1231413412

But this doesn't seem to work with my Verilog compiler

3
  • what does 16#0# mean? I know SystemVerilog, but I'm not very familiar with VHDL Commented Feb 16, 2016 at 23:23
  • No. 16#0# is a based literal (IEEE Std 1075-2008 15.5.3 Based literals). The meaning of that expression is 0 in base 16 (0). If you're trying to define an array value of 16 '0's that would be along the lines of 16d"0". (0 is not a character enumeration and this is a bit string literal (15.8). Commented Feb 16, 2016 at 23:37
  • That could be constant X: std_logic_vector (WIDTH -1 downto 0) := (others => '0'); Commented Feb 17, 2016 at 3:38

2 Answers 2

1

It Verilog, it's rare that you need to specify the width of an unsigned constant. But if you did need to, it would be:

parameter WIDTH = 16
parameter bit [WIDTH-1:0] X = 'd1231413412

Note that once you define a parameter with a data type, you can only override its value, not its type.

Sign up to request clarification or add additional context in comments.

Comments

1

It should be something like the following:

parameter WIDTH = 16;
parameter [WIDTH-1:0] X = 0;

It will work with SystemVerilog (IEEE1800) and Verilog since 2001 (IEEE1364-2001). If you are stuck with an archaic simulator that only supports Verilog 1995 (IEEE1364-1995), it will not work.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.