System Verilog Oop Assignment

Download as pdf or txt
Download as pdf or txt
You are on page 1of 5

SYSTEM VERILOG OOP ASSIGNMENT

1. Counting of serial number from 0 to 9 using classes


class demo;
int i;
int numb;
task counting();
$display("The serial numbers are");
for(i=0;i<10;i++)
begin
numb=i;
$display("%d\n",numb);
end
endtask
endclass
module top_count;
initial
begin
demo d1;
d1=new();
d1.counting();
end
endmodule
TRANSCRIPT:
The serial numbers are
# 0
# 1
# 2
# 3
# 4
# 5
# 6
# 7
# 8
# 9

2. Display the sum of two numbers using class;


class demo;
task sum(input int a, b, output int c);
c=a+b;
$display("%d",c);
endtask
endclass
module top_count;
initial
begin
int x;
demo d1;
d1=new();
d1.sum(10,20,x);
end
endmodule
TRANSCRIPT:
run
# 30
3. Creating two Objects of class.
class demo3;
int i;
int j;
task disp();
begin
$display("the value of i=%d value of j=%d",i,j);
end
endtask
endclass
module top3;
initial
begin
demo3 d1,d2;
d1=new();
d2=new();
d1.i=50;
d1.j=55;
d2.i=15;
d2.j=35;
d1.disp();
d2.disp();
end
endmodule
TRANSCRIPT:
# the value of i= 50 value of j= 55
# the value of i= 15 value of j= 35
4. Using LOCAL in the class.
class demo3;
local int i=10;
local int j=20;
task disp();
begin
$display("the value of i=%d value of j=%d",i,j);
end
endtask
endclass
module top_count;
initial
begin
demo3 d1,d2;
d1=new();
d2=new();
d1.i=50;
d1.j=55;
d2.i=15;
d2.j=35;
d1.disp();
d2.disp();
end
endmodule
TRANSCRIPT:
# vlog -reportprogress 300 -work work C:/questasim64_10.6c/examples/top_count.sv
# -- Compiling package top_count_sv_unit
# -- Compiling module top_count
# ** Error (suppressible): (vlog-8688) C:/questasim64_10.6c/examples/top_count.sv(16):
Illegal access to local member i.
# Full name of member: top_count_sv_unit::demo3::i
# Full name of calling scope: outside a class context
# ** Error (suppressible): (vlog-8688) C:/questasim64_10.6c/examples/top_count.sv(17):
Illegal access to local member j.
# Full name of member: top_count_sv_unit::demo3::j
# Full name of calling scope: outside a class context
# ** Error (suppressible): (vlog-8688) C:/questasim64_10.6c/examples/top_count.sv(18):
Illegal access to local member i.
# Full name of member: top_count_sv_unit::demo3::i
# Full name of calling scope: outside a class context
# ** Error (suppressible): (vlog-8688) C:/questasim64_10.6c/examples/top_count.sv(19):
Illegal access to local member j.
# Full name of member: top_count_sv_unit::demo3::j
# Full name of calling scope: outside a class context
# End time: 14:52:12 on May 20,2020, Elapsed time: 0:00:01
# Errors: 4, Warnings: 0
INFERENCE: Using the LOCAL keyword the integer variable I and j are made private
to this particular class and the entertain no changes outside of the class.

You might also like