You are on page 1of 2

High Level Verification with SystemVerilog SV Datatype

SV Datatype Lab Exercise


Lab 11: Enumerated Type
Abhishek Kumar Singh | EVD18I031

Problem Statement
An ALU has the following opcodes.

Write a testbench that performs the following tasks.


1. Create an enumerated type of the opcodes, opcode_e
2. Create a variable, opcode , of type opcode_e
3. Loop through all the values of variable opcode every 10ns
4. Instantiate an ALU with one 2 bit input opcode

Goal: Write SV code, simulate and verify manually. Submit your SV code and log

Solution
The ALU instantiation is commented in the initial block.

Code:
module enumtype();

typedef enum bit [1:0] {add=2'b0, sub=2'b01,


bitwise_invert_A=2'b10,
reduction_or_B=2'b11} opcode_e;

1
High Level Verification with SystemVerilog SV Datatype

opcode_e opcode;

initial begin
opcode = opcode.first;

do begin
$display("Opcode=%b:%s", opcode, opcode.name());
opcode=opcode.next;
#10;
end
while(opcode!=opcode.first);

end

//alu ALU1 (.opcode(opcode));

endmodule

Log:
[2022-04-02 06:18:45 UTC] xrun -Q -unbuffered '-timescale' '1ns/1ns' '-sysv' '-access'
'+rw' design.sv testbench.sv
TOOL: xrun 20.09-s003: Started on Apr 02, 2022 at 02:18:45 EDT
xrun: 20.09-s003: (c) Copyright 1995-2020 Cadence Design Systems, Inc.
Top level design units:
enumtype
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.enumtype:sv .................... Done
xmsim: *W,DSEM2009: This SystemVerilog design is simulated as per IEEE 1800-2009
SystemVerilog simulation semantics. Use -disable_sem2009 option for turning off SV
2009 simulation semantics.
xcelium> source /xcelium20.09/tools/xcelium/files/xmsimrc
xcelium> run
Opcode=00:add
Opcode=01:sub
Opcode=10:bitwise_invert_A
Opcode=11:reduction_or_B
xmsim: *W,RNQUIE: Simulation is complete.
xcelium> exit
TOOL: xrun 20.09-s003: Exiting on Apr 02, 2022 at 02:18:46 EDT (total: 00:00:01)
Done
★★★

You might also like