Anda di halaman 1dari 3

1.

Given the following code sample:


byte dt_byte;
integer dt_integer = 32’b000_1111_xxxx_zzzz;
int dt_int = dt_integer;
bit [15:0] dt_bit = 16’h8000;
shortint dt_short_int1= dt_bit;
shortint dt_short_int2 = dt_short_int1-1;
 What is the range of values dt_byte can take?
 What is the value of:
o dt_int in hex?
o dt_bit in decimal
o dt_short_int1 in decimal
o dt_short_int2 in decimal
2. Write the SystemVerilog code to:
 Declare a 2-state array, dt_array, that holds four 12-bit values
 initialize dt_array so that:
o dt_array[0] = 12’h012
o dt_array[1] = 12’h345,
o dt_array[2] = 12’h678,
o dt_array[3] = 12’h9AB;
 Traverse dt_array and print out bits [5:4] of each 12-bit element
o Using a for loop
o Using a foreach loop
3. Write the SystemVerilog code to:
 Declare a 2-state integer dynamic array, dt_darray and allocate the
size of 10 elements
 Perform following operations on queue:
o Initialize the elements of array with random values
o Print the size of the array and its elements
o Copy dynamic array dt_darray in to another dynamic array
dt_darray_copy[]
o Double the size of the dynamic array dt_darray and keeping the
content of initial 10 locations same as previous
4. Use multi-dimensional array to implement a memory. Initialize and print
its content. Pack the array, access least 3 bytes, complement them and
again store at the same locations.
5. Add 50 integer values at random locations (between 1 to 100) of an
integer associative array.
 Check value at index 2 and 45 exists.
 Print the value at first index along with index.
 Print the value at last index along with index.
 Check the array size.
th th th
 Delete 5 , 10 and 15 index if they exist.
 Print array size again.
6. Declare an integer queue. Initialize it with five elements (0 to 4).
 Insert an element at beginning without any method
 Insert an element at beginning using predefined queue method
 Insert an element at the end using predefined queue method
 Insert an element at index-4
st
 Get 1 element in queue
 Get last element in queue
 Delete an element at index-4 in queue
 Shuffle the queue
 Sort the queue
 Reverse Sort the queue
Use a method to print queue after each of the above operations.
7. Write a code to multiply a loop variable by 2 starting from 1 to 25. Use
break and continue in the loops to control the loop flow and print
statements for the result.
8. Write a constraint to generate only ODD number of values in the range (1,
1000) for a random variable ‘int unsigned x’.
9. Write a constraint to generate discrete value in the range (5, 10) and (15,
20) for for a random unsigned integer variable ‘x’.
10. Write a constraint to generate unique value for each elements of
dynamic array variable ‘int unsigned a[]’ with array size constrained to 10
11. Write a constraint to generate one-hot value for a random 32-bit
variable ‘bit [31:0] a’.
12. Write a function to calculate ODD or EVEN parity for each element
of the unsigned integer array ‘rand bit [31:0] a[20]’ and return the
calculated parity in an bit array ‘bit parity[20]’ in the calling code.
13. Implement a static method inside the class that prints the count for
total number of objects being created.
14. Create a class called “Transaction’ that contains the following
members:
 An 8-bit data_in of logic type
 A 4-bit address of logic type
 A 4-bit static variable ‘last_address’ that holds the initial value of
the address variable from the most recently created object, as set
in the constructor.
 Create a void function ’print’ that prints out the value of data_in
and address
 Create a static method called ‘print_last_address’ that prints out
the value of static variable last_address
 Construct a ‘Transaction’ object in an initial block
 Create a constructor so that data_in and address are both
initialized to 0 but can also be initialized through arguments
passed into the constructor.
 Create 2 new Transaction objects using handles t1, t2
o Initialize address to 2 in the 1st object, passing arguments by
name
o Initialize data_in to 3 and address to 4 in the 2nd object, passing
arguments by name.
o Use the print function to print out the values of data_in and
address for the 2 objects.
o Print out the current value of ‘last_address’ using method
‘print_last_address’
o Explicitly deallocate the 2nd object.
15. Write a code to perform deep copy and shallow copy of the class
‘Transaction’ containing handle of class ‘Statistics’ within it.
 Class ‘Transaction’ has following properties:
o bit [31:0] addr;
o static int count = 0;
o int id;
o Statistics stats;
 Class ‘Statistics’ has following property:
o time startT; //Transaction start time

Anda mungkin juga menyukai