SV ASSESSMENT
1. If the following code is executed, what will the output look like.
fork
begin
repeat(3)@(posedge CLOCK);
$display(“Hello 1\n”);
end
begin
repeat(1)@(posedge CLOCK);
$display(“Hello 2\n”);
end
join_any
$display(“Hello 3\n”);
repeat(1)@(posedge CLOCK);
$display(“Hello 4\n”);
2. Write a class which has two 32-bit variables A and B and follows the below listed rules. Have each rule under a
separate constraint.
a) Both A and B can be integer values between 0 and 100.
b) At a time one of them can be an odd number.
c) Sum of both numbers should be always 150.
d) If one of them is falling into the range 95 to 100 other should be 0.
3. Create an extended class from above class and it should allow the case where A+B is greater than 150.
4. Write code to accomplish this specific randomization of the above extended class where A+B is greater than
500.
5. Implement a simple memory model which has 2 banks, 16 rows, 16 columns. Each column can store a bit.
[Hint: Memory model has the memory array, tasks for reading and writing from the memory]
6. Write the body of the task which takes an input bus of 64 bits and 256 bits and return the list of bytes as output.
(first 8 bytes of the outputs are from 64 bits and the remaining from 256 bits. Below is the task declaration.
task (input [63:0] in1, bit [255:0] in2, byte out[]);
7. Write code for below requirements. Assume that write_mem and read_mem are already defined.
a) Thread1 should have a while(1) loop within which it calls a function called read_mem which is passed in a
random aligned 16 bit address and returns 32 bit data. The random address is generated in each loop.
b) Thread2 should have a while(1) loop should call a function called write_mem which is passed in a random
aligned 16 bit address and a random 32 bit data.
c) If read_mem returns data>32’hf000 then it should terminate both threads.
d) At any time, only one thread should be accessing memory.
8.
a) Create a class called Packet. This class should have one field of type integer called id.
b) Create a class called scoreboard1
This class should instantiate a queue of Packets.
The scoreboard should have a task insert_packet which will take a Packet argument and insert the
Packet into the end of the queue.
The scoreboard should have a function return_last_packet which will return Packet from the end of its
queue.
The scoreboard should have a function check_if_packet exists which will be passed in an id and it will
return 1 if exists in one of its Packets else it will return 0.
c) Create a class called scoreboard2
This class should instantiate a static array of 16 data structures which can store objects of type Packet.
Write a task create_packets that news and creates the elements in static array.
9. Is there a problem with this code? If so, list them.
class Packet
local integer a;
protected task print()
$display(“a=%0d\n”,a);
endtask
endclass
class EtherPacket extends Packet;
local task print2()
print();
endtask
endclass
10. Create the below class as per requirements.
Class name is transaction.
Class has the following attributes: type, address (32 bits), payload (1-1024 bytes).
Transaction can be one of 3 types READ, WRITE or IDLE.
Transaction type should be random and should be READ 40% of the time, WRITE 50% of the time and IDLE
10% of the time.
Payload is a byte array of random size between 1-1024.
if type is READ then lsb 8 bits of address field should be greater than 50 but less than 120.
if type is WRITE then lsb 8 bits of address field should not be ff, ee, dd, cc, bb or aa.
If type is IDLE then address field should be 0.
if type is READ or type is IDLE then payload should have 0 size.
11. Add a copy task in the above class that copies the contents to the passed class handle. Remember that the
passed class handle can be either NULL or new-ed already.
12. Answer the questions on the following code snippet.
class Automobile;
virtual task display();
$display(“I AM AN AUTOMOBILE\n”);
endtask
endclass
class Car extends Automobile;
task display();
$display(“I AM A CAR\n”);
endtask
endclass
class Maruti extends Car;
task display();
$display(“I AM A MARUTI\n”);
endtask
endclass
//a) What’s the output in this case?
program main;
Car car;
Maruti maruti=new;
initial begin
car=maruti;
car.display();
end
endprogram
//b) What’s the output in this case?
program main;
Car car=new;
initial begin
auto=car;
auto.display();
end
endprogram
//c) What’s the output in this case?
program main;
Automobile auto;
Maruti maruti=new;
initial begin
auto=maruti;
auto.display();
end
endprogram