You are on page 1of 6

Dynamic Array:

1. Create a dynamic array D_arr of integer type.


2. Store 100 elements (0 to 99) to D_arr.
3. Copy this to another dynamic array D_arr_n of size 150. First 100 elements of this array
should be same as the previous array elements. Add the new elements of this array D_arr_n
as 100 to 150.
4. Display the size of both the arrays.
5. Pick any random element from D_arr_n.
6. Display the sum of all elements in both the arrays.
7. Reverse the elements in D_arr_n and display all the elements.
8. Delete all the elements of D_arr.
9. Create a dynamic array to store 4 words (16 bit) of data.

Queue :
1. Create an integer queue Q with the following 10 elements, {
10,20,30,40,50,60,70,80,90,100 }.
2. Create another queue Q_n which can hold maximum of 20 elements.
3. Copy Q to Q_n. Also add another 10 elements as {110..120]. Try adding one more
element to this queue.
4. Display the first and last element & size of Q_n.
5. Shrink the size of the queue to 5 elements without using the delete method?
Display the size of the queue Q_n.
6. Enter an element each at the head and the tail of the queue Q_n. Display all the
elements.
7. Remove the added elements from the head and the tail of the queue Q_n. Display all
the elements.
8. Copy this queue Q_n to a dynamic array D_n.
9. Create a dynamic array of queues. Let the array have 2 elements and then add 1
element each in the queue. Display the entire structure.

Associative array:

1. Create an associative array assoc_arr with integer index and which stores byte
elements.
2. Add 5 elements to the array. Display all the elements and size of this array
3. Pick and display one random element of this array.
4. Create another associative array assoc_arr1 to have both integer and string as
index. Store elements (1...10).Use integer indexes for all the odd numbers and string
indexes for even numbers.
5. If the array assoc_arr1 contains an element with index ten display Index ten
Exists.
6. Consider the following database in the format, {Name, Runs, Wickets, Catches} for
Indian cricket players :
Sachin=(726,0,6), Sewag=(700,3,4), Raina=(424,5,6), Dhoni=(546,0,10), Yuvraj =(467,9,7),
Zaheer=(64,12,6), Aswin=(23,15,5). store it using an associative array with name as the
index.
Mailbox

1. Create a mailbox mbx which can hold maximum of 10 integer values.


2. Create a put task, which continuously generates random integer values and puts in to the
mailbox without any delay.
3. Create a get task, which gets the packets from mailbox and displays.
4. Now modify the get task so as to fetch an item from the mailbox only if there are 3 or
more items in the mailbox. Create a new task copy, which should copy the items in the
mailbox to a dynamic array. Display the contents at the end of test.
5. Modify the put task to have #50 delays before putting a packet to mailbox.
6. Write a get_nb task, which fetches an item from the mailbox if present. If the mailbox is
empty display Waiting for data item and wait for #10. Repeat the above sequence.
NOTE: There are 4 tasks in this lab (put,get,get_nb & copy). All these tasks should be
started in parallel. The test can be made to stop after a delay of #500.

Semaphore , Events and fork/join


Exercise 1:

1. Implement a memory mem with 32 bit data lines and 8 bit address lines using system
Verilog constructs.
2. Create 2 tasks write and read. Both of them should be run in parallel.
3. write task should generate random addr & data values and then write to mem.
4. read task to read the data from memory using the random addr generated.
5. Use a semaphore to lock the mem if any one of the tasks is using it.
6 Make the execution of write and read tasks in an ordered way such that read access to
mem happens only after the write access.

Exercise 2:

1. Create three tasks: put, get & count and a mailbox mbx.
2. The task put should generate random data and save in the mailbox.
3. The task get should retrieve data from the mailbox and store it to a local variable. Iif the
data is divisible by 5, then this task should terminate.
4. The task count should wait for the get task to store the data into local storage. If the data
stored is an even number then increment a local counter. If the counter value reaches 6
terminate the loop.
5. After any of the get or count task gets terminated, there should be a display saying which
task got terminated.

Exercise 3:

1 Create the following tasks: put, get, data_collecter, data_checker, even_seq_det &
odd_seq_det.
2 Also create a
a. Mail box mbx to hold integer data.
b. Queues Q, O_Q & E_Q of integer type
c. Events gen_ev, odd_ev, even_ev, odd_data_ev & even_data_ev
3 The put task should generate random positive numbers and store into the mailbox.
4. The get task should retrieve the data from mailbox, save it into the queue Q and then
generate an event gen_ev.
5. The data_collector task should wait for gen_ev. Once it is triggered pick the data from
the queue and delete the queue element.
a. If the data has odd number of ones then put it into the queue O_Q, then generate
event odd_ev.
b. If the data has even number of ones then put it into the queue E_Q then generate
event even_ev.
6. The data_checker task should wait for any of the events odd_ev or even_ev. Based on
the event triggered pick the data from respective queues (& delete the queue elements). If
the data is an odd data generate event odd_data_ev, otherwise generate even_data_ev.
7. The even_seq_det task should to detect the following sequence and display Even
sequence Detected.
Put task generates a data -> Data collector detects even parity-> data checker
detects even number.
8. The odd_seq_det task should detect the following sequence and display Odd sequence
Detected.

Put task generates a data -> Data collector detects odd parity-> data checker detects
odd number.
9. Once both the sequences are detected atleast once, stop generating more data. Then
display which sequence was detected first.

Objects creation, property and methods

1. Implement a class with the following,


Name: A.
Properties: val_a & val_b of integer type. Constructer should take care of initializing these
values.

2. Implement a class with the following,

Name: base.

Properties:
obj_id of integer type this should unique for every object that is being created. It
can be in incremental order i.e. for the 5th object created the value of obj_id
should be 5.
Also this should not be accessible from anywhere outside this class.
cls_id of integer type which any class handle should be able to access without
creating an object
val_b and val_i of integer type. Both should be accessible within this class and
also its child.
A_inst a handle of the class A.

Methods:
get_id : This should return the value of obj_id
mem_alloc : This function allocates memory to the base type. It should have one input
argument of base type. If this handle is null then this method should allocate memory for
the handle that is passed, else return the value of obj_ id of the object referred by the
handle.
set_val : This function takes two input arguments of integer type and assigns the input
values to val_b and val_i.
get_val : This function should display the values of val_i and val_b.

Create a dynamic array base_arr of type base. This array should hold 10 elements.
1. Update the cls_id field for all the elements to have different values.
2. Generate objects for this array and display the obj_id of each.
3. Create a new handle base_i of class base. Allocate memory to this handle using the 2
element of base_arr.
4. Modify the A_inst property values in base_i and display.

Copying object:

Perform the following Copy operation using the two handle base_orig (create an new object
) & base_rep (only handle declaration) of class base type:
Case 1: both the handles base_orig & base_rep should have shared access to
A_inst. Prove that both handles are accessing the same A_inst object.
Case 2: both the handle base_orig & base_rep has shared access to A_inst, but
standalone access to val_b & val_i.
Prove that both handles are accessing the same A_inst object but different val_b & val_i
Case 3: both the handles have standalone access to A_inst as well as to val_b &
val_i.

Prove that both handles are accessing different A_inst object as well as different val_b &
val_i integer values.

Inheritance & polymorrhism


1. Create a child class which has all the properties of base.
a. Add two new properties val_b and val_i to the child.
b. The set_val method of child should set values for both child and base. The base
values should incremental of the child values.
c. The get_val method should display the values of val_i and val_b in both the base
and child.
2. Create an object of child class, set the values of val_i and val_b to be 10 and 20 &
display all the values.
3. Create the base handle b. Now assign the previously created child object to b.
4. Display the values of val_i & val_b in base and child using this base handle b.
5. Create another child handle c1. Assign b to c1. Use c1 to display all the properties of
child class.

Parameterised class:

1. Create a configurable class which should have a queue and two methods for writing into
the queue and reading from the queue. The configuration details are as follows,
Configuration 1 -> the queue should hold integer data types.
Configuration 2 -> the queue should hold string data type.
2. Create two instances one for each configuration and try write & read operations with
respective data types.

Basic constraint and randomization methods

1. Implement a class with the following,


Name: packet
Properties:
addr - 32 bits
data - dynamic array of integers.
mode - should be an enumerated type with values { idle,busy,write,read,resp}.
xfer_id - 4 bits, transfer id unique for each transaction. Should start with any random value,
then should generate all possible random values before repeating the cycle.
Methods:
. display Displays all the property values for this class.
Constraints:
c1 - addr is always double word (32 bit) aligned.
c2 - addr can be any value other than the range hF000 to h1_0000.
Packets within addr range h0000 to h8000 & h1000_0000 to hFFFF_FFF0 should be
generated once in every 2 packets
c3 - Size of data should be 0 for busy & read types.
c4 - Size of data should be always less than 128 and greater than 0.
c5 - Data items are always from the group {
h00,hAA,hBB,hCC.hDD,h44,88,hFF,h11,h22}.

2. Create an object obj of packet type. Generate 10 random packets using the same object
and display the properties.
3. Now generate 10 packets of same values using the same object.
4. Now generate 10 packets with same addr value and different values to other properties
using the same object.
5. Now generate a packet with data size to be 256 without modifying the packet class.

Dynamic constraint modification

1. Implement the following class


Name: parent
Properties: integer a & b.
Constraints:
c1 -> a should be greater than 10.
c2 -> b should be less than 5.
Methods:
display -> display the property values.
2. Create an object of this class, generate 10 sets of random values for the class properties
and display
3. Create another class which is inherited from parent class with following,

Name: child.
Properties: mode 2 bits should not be random.
Constraints:
c3: a=0 & b=0.
c4: a >10 & b<5.
c5: a>10&a<100, b<5 & b>1.
c6: a=100 & b=50.
Create an object of child class; generate 10 sets of random values and display.
1. Using the inbuilt randomize functions for the same objects generate a=0 and b=0.
2. Using the inbuilt randomize functions for the same objects generate a=15 and b=0.
3. Using the inbuilt randomize functions for the same objects generate a=50 and b=4.
4. Using the inbuilt randomize functions for the same objects generate a=100 and b=50.

Functional coverage

1. Use the same packet class from LAB4.


2. Add a new method event_gen. This method should generate an event cov_ev at every
20ns.

3. Create the following coverage model for this packet.


a. addr is always double word aligned, if not it should generate an error.
b. Following ranges of addr is generated.
Min -> h0000_0000 to h0000_EFFFF
Mid -> h1_0004 to h 1000_FFFF
Max -> hF000_0000 to hFFFF_FFF0
c. All possible values of xfer_id.
d. All possible values of mode except idle.
e. addr in the Min range occurs for all xfer_id values.
f. xfer_id 0 to 7 occurs for all modes.

4. The coverage collection should happen at every cov_ev event.


5. Create an object of packet class and keep generating random packets after every 15ns
until the coverage score is 60%.
6. Make the addr field in the object to be h3, then force the coverage sampling.

You might also like