SystemVerilog bit datatype - EDA Playground
Warning! This exercise has been opened in another tab; autosave has been disabled. Close this tab or refresh to reactivate.

 Languages & Libraries

 Tools & Simulators

 Examples

202


40
 
1
module tb;
2
  bit       var_a;       // Declare a 1 bit variable of type "bit"
3
  bit [3:0] var_b;       // Declare a 4 bit variable of type "bit"
4
  
5
  logic [3:0] x_val;     // Declare a 4 bit variable of type "logic"
6
  
7
  initial begin
8
  
9
    // Initial value of "bit" data type is 0
10
    $display ("Initial value var_a=%0b var_b=0x%0h", var_a, var_b);
11
    
12
    // Assign new values and display the variable to see that it gets the new values
13
    var_a = 1;
14
    var_b = 4'hF;
15
    $display ("New values    var_a=%0b var_b=0x%0h", var_a, var_b);
16
    
17
    // If a "bit" type variable is assigned with a value greater than it can hold
18
    // the left most bits are truncated. In this case, var_b can hold only 4 bits
19
    // and hence 'h481 gets truncated leaving var_b with only 'ha;
20
    var_b = 16'h481a;
21
    $display ("Truncated value: var_b=0x%0h", var_b);
22
    
23
    // If a logic type or any 4-state variable assigns its value to a "bit" type 
24
    // variable, then X and Z get converted to zero
25
    var_b = 4'b01zx;
26
    $display ("var_b = %b", var_b);
27
  end
28
endmodule
29
30
/*
31
Simulation Log:
32
---------------
33
ncsim> run
34
Initial value var_a=0 var_b=0x0
35
New values    var_a=1 var_b=0xf
36
Truncated value: var_b=0xa
37
var_b = 0100
38
ncsim: *W,RNQUIE: Simulation is complete.
39
ncsim> exit
40
*/
xxxxxxxxxx
1
 
1
// Code your design here
2
1184 views and 0 likes     
A short description will be helpful for you to remember your playground's details
 
100:0