Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

$size, $bits, verilog

What is the difference between $size and $bits operator in verilog.? if I've variables, [9:0]a,[6:0]b,[31:0]c.

c <= [($size(a)+$size(b)-1]-:$bits(b)];

What will be the output at 'c' from the above expression?

like image 233
Suhas Avatar asked Nov 12 '12 08:11

Suhas


People also ask

What is $bits in Verilog?

$bits. The $bits() system function returns the number of bits required to hold an expression as a bit stream. In the example below it is used to get the bitstream size of a struct and an array. One big advantage of the $bits() function is that it can be used as an elaboration time constant.

How do you assign a value to a vector in Verilog?

Bit Selects Any bit in a vectored variable can be individually selected and assigned a new value, as shown in the below image. This is called a bit select. If the bit select is out of bounds or the bit select is x or z, then the value returned will be x.

How do you represent register data in Verilog?

Register data types are used as variables in procedural blocks. They store logic values only (no logic strength). A register data type must be used when the signal is on the left-hand side of a procedural assignment. Verilog-2001 adds the ability to initialize variables at the time they are declared.

How do I select a part in Verilog?

Part-selects A range of contiguous bits can be selected and is known as a part-select. There are two types of part-selects, one with a constant part-select and another with an indexed part-select. Having a variable part-select allows it to be used effectively in loops to select parts of the vector.


1 Answers

$size() gives the number of bits for a single dimension. $bits() gives the number of bits to completely represent the variable.

For example:

reg [9:0] a;
reg [9:0] b [5:0];

initial begin
  $display("a Size ", $size(a));
  $display("a Bits ", $bits(a));
  $display("b Size ", $size(b));
  $display("b Bits ", $bits(b)) ;
end

Gives :

a Size          10
a Bits          10
b Size           6 // Depth of memory
b Bits          60 // Width * Depth

In your case you just have 1 dimensional arrays, not memories or structs so $size() and $bits() would be the same thing.

like image 54
Morgan Avatar answered Sep 20 '22 05:09

Morgan