Professional Documents
Culture Documents
SV Datatype Lab Exercise
SV Datatype Lab Exercise
SV Datatype Lab Exercise
Problem Statement
1. Create a user defined type, nibble_t , of 4 bits
2. Create a real variable, r , and initialize it to 4.33
3. Create a short int variable, i_pack
4. Create an unpacked array, k , containing 4 elements of your user defined type
nibble and initialize it to 4’h0, 4’hF, 4’hE, and 4’hD
5. Print out k
6. Stream k into i_pack right to left on a bit basis and print out i_pack
7. Stream k into i_pack right to left on a nibble basis and print out i_pack
8. Type convert real r into a nibble, assign it to k[0] 0], and print out k
Goal: Write SV code, simulate and verify manually. Submit your SV code and log
Solution
‘typedef ’ was used to create a user-defined datatype ‘nibble_t’. real and short int variables were
also created according to syntax rules. Unpacked array declaration was used to create a 4
element array k and initialized with given values.
Then array k is streamed into the i_pack variable. In bit-wise it’s 1011_0111_1111_0000. So
reading it from right to left, we have 0, 15, 14 and 13. In nibble-wise it’s 1101_1110_1111_0000.
So reading it from right to left, with 4 bits at a time, we have 0, 15, 14 and 13.
Finally r is converted from real type to nibble type and it’s assigned value k[0].
Simulation
module userdata();
1
High Level Verification with SystemVerilog SV Datatype
initial begin
$display("---Array: k---");
foreach(k[i])
$display("%b", k[i]);
$display("---i_pack(bit basis)---");
i_pack = { <<{k}};
$display("%b", i_pack);
$display("---i_pack(nibble basis)---");
i_pack = { << nibble_t {k}};
$display("%b", i_pack);
$display("---Array: k---");
foreach(k[i])
$display("%b", k[i]);
end
endmodule
Log:
[2022-03-31 05:59:36 UTC] xrun -Q -unbuffered '-timescale' '1ns/1ns' '-sysv' '-access'
'+rw' design.sv testbench.sv
TOOL: xrun 20.09-s003: Started on Mar 31, 2022 at 01:59:37 EDT
xrun: 20.09-s003: (c) Copyright 1995-2020 Cadence Design Systems, Inc.
Top level design units:
userdata
xmelab: *W,DSEMEL: This SystemVerilog design will be simulated as per IEEE 1800-2009
SystemVerilog simulation semantics. Use -disable_sem2009 option for turning off SV
2009 simulation semantics.
Loading snapshot worklib.userdata:sv .................... Done
2
High Level Verification with SystemVerilog SV Datatype