Training
SYSTEMVERILOG ASSIGNMENT-2
Q.No. Questions (Arrays, Queue and Array Methods)
1) a) To understand the difference between packed and unpacked array
Declare unpacked arrays with different size
- int a[4:0], b[4:0], c[4:0], d[1:0], e[1:5]
• Assign the value for array a, b by using array interals
• Perform the following and check the result
- and, or , xor //c=a&b
- assign value to another array // e=a;
- bit slice // d=b;
- randomize array values // e[1:0]=$urandom_range(0,100);
b) Perform the above steps with packed arrays (bit [4:0]a; bit [4:0]b, bit
[4:0]c, bit [1:0]d, bit [1:5]e) and analyse the results
https://www.edaplayground.com/x/saJL [Note: packed array should
be a single bit data type]
2) a) Multi dimensional Array
• Declare a mem1: 1kb with depth 64, each element of size 16 bits
• Declare mem2: reg[7:0][9:0]mem2[8][6:0];
• Randomize the elements of mem2
• Print using single display
• Print using for loop
• Print the elements of mem2[6]
• Print the elements of mem2[6][2]
• Print the elements of mem2[6][2][1]
• Print the elements of mem2[6][2][1][4]
https://www.edaplayground.com/x/QTE9
3) a) Associative Array
Declare associative array int type //int asa[*];
• Declare int a,b
• Randomize variable a,b
Put the values in asa //take ‘a’ as index and ‘b’ as value
• Print it
• Print number of entries
• Print in reverse order // use associative array methods
• Delete a particular index value and print
b)
Queue
• Declare queues of int type with size 10 // int Q[$:9];
• Put the value of associative array into Q and sort
• Do reverse sort and print
https://www.edaplayground.com/x/f9QS
4) a) Design a Content Addressable Memory (CAM) using associative array
Declare a memory: 3bit associative array index type byte
//bit [2:0]mem[byte];
• Put the content inside the mem for corresponding index
• Print the whole mem
• Print the content of a specific index
• Check content is present or not in a specific index
• Print the last content and index of the mem
• Check specific value is present or not in the mem, if present print the
index of that value https://www.edaplayground.com/x/PUqF
5) a) Accessing random element of queue
Declare a queue with bounded size
• Declare int type intx and temp variable
• Assign values for the queue
Print all the element along with its index
• Print the size of the queue
• Randomize the intx and print the value of the queue randomly
• Delete some random index of the queue and print the size
• Insert a new value in middle of the queue
b) Using push_front(), push_back(), pop_front() and pop_back() method to
add and remove the elements
• Delete the complete queue
• Print the size of the queue https://www.edaplayground.com/x/FP8i
6) a) Implement a simple FIFO with queue
Inputs: data_in, w_fifo, r_fifo; Outputs: empty, full, data_out
• Use queue methods to perform write and remove values from queue
• Verify the functionality of the FIFO
https://www.edaplayground.com/x/7qF4
b) Implement stack using queue as above
https://www.edaplayground.com/x/aqBM
7) a) Randomize a dynamic array without using the randomization methods
such that all the values should be within 10 to 100 and the size of the
array should be less than 15.
https://www.edaplayground.com/x/t2Xw
8) a) Struct (static data types) Declare below struct datatype typedef
struct{ int age; string name; byte exp; string address; bit
status;
} employee_t;
• Declare array of employee record of 10 employees
• Assign age, exp, randomly
• Sort the employee record for various requirements
- Based on age
- Based on exp
- Based on age with specific status
https://www.edaplayground.com/x/QZP2
9) a) Create a struct data type: medals_t
- int gold, silver, bronze
• Create an array of 5 struct elements
• Randomly populate medals tally for each country with range
• Print all the elements of array
• Find all countries with total medals more than 70
• Arrange all countries medals with descending order
• Find all countries who has more bronze medals than gold medals
• Find first country with more than 25 golds
• Find last country with less than 60 medals
• Sort medals array, total medals as criteria
• Do reverse sort
• Shuffle
• Declare an integer array with size 8
• Get the sum of all the elements in array
• Get the product of all the elements in array
https://www.edaplayground.com/x/bMxj