1BM22EC211
1BM22EC211
S COLLEGE OF ENGINEERING
(Autonomous college Affiliated to Visvesvaraya Technology University, Belgaum)
BullTemple Road, Basavanagudi, Bangalore-560019
AAT - 1 Assignment
Submitted for the partial fulfillment of the requirement of Alternate Assessment for the
course
BACHELOR OF ENGINEERING
In
SAHARSHA 1BM22EC211
2024 – 2025
Course Co-ordinator
Acknowledgement: This work was carried out with the EDA tools provided by Meity, Govt. of India,
under C2S funding.
1
Assignment 1
Implement T flipflop and test it using system Verilog test bench with
interface, modport clocking block and top module
Introduction:
This project focuses on the implementation and verification of a T (Toggle) flip-flop using
Verilog and a structured SystemVerilog testbench. The T flip-flop toggles its output on each
clock edge when the T input is high, making it useful in counters and control systems.
The testbench uses SystemVerilog features like interface, modport, and clocking block to
organize signal connections and ensure accurate timing. A top module integrates the T flip-
flop and testbench components, providing a clean and reusable design structure.
This setup enables thorough and efficient verification of the T flip-flop’s behavior under
various conditions.
Codes:
T_Flipflop:
// T_FF module with asynchronous active high reset and synchronous active high set
module T_FF(T_inter.RTL R1);
endmodule
Interface block:
2
logic t; // Toggle input
logic set; // Synchronous set input
logic reset; // Asynchronous reset input
logic q; // Output of T flip-flop
endinterface
Testbench :
//Test bench
module Test(T_inter.TB T1);
initial
begin
T1.set=0;T1.reset=0;T1.t=0;
#10 T1.reset=1;
#10
T1.reset=0;
#10
T1.set=1;
#10
T1.set=0;
#10
T1.t=1;
#10
T1.t=0;
#10
T1.t=1;
#100 $finish;
end
endmodule
3
Top module:
// Top module to connect T Flip-Flop DUT and Testbench via interface
module Top;
// Instantiate the Test module and bind it to the TB modport of the interface
Test inst1(I1.TB);
// Instantiate the T_FF module (Design Under Test) and bind to RTL modport of the
interface
T_FF DUT(I1.RTL);
// Clock generation: toggle every 5 time units to create a 10-time-unit period clock
always #5 clk = ~clk;
endmodule
Simulation output:
4
Coverage report:
5
Assignment 2
Implement 8-bit ALU and test it using system Verilog test bench with
interface, mod port, clocking block and top module
Introduction:
This project focuses on the design and verification of an 8-bit Arithmetic Logic Unit (ALU)
using Verilog and SystemVerilog. The ALU is capable of performing a range of arithmetic and
logical operations such as addition, subtraction, AND, OR, XOR, and more, based on a control
input.
To ensure a modular and scalable verification environment, the testbench is built using
SystemVerilog constructs such as interface, modport, and clocking block. The interface
groups related signals, while modports define directionality for design and testbench roles. The
clocking block ensures proper synchronization of stimulus with the clock signal. A top module
integrates the ALU, interface, and test logic for simulation.
This approach not only verifies the correctness of the ALU under various input conditions but
also demonstrates best practices in structured digital design and verification.
Codes:
ALU block:
6
end
endmodule
Interface block:
// ALU signals
logic [7:0] a, b; // 8-bit input operands
logic [2:0] op; // 3-bit opcode to select the ALU operation
logic [7:0] result; // 8-bit result output
logic valid; // Output valid signal
endinterface
Testbench :
bit [7:0] a, b;
int i = 0;
7
initial begin
a = $urandom_range(0, 255);
b = $urandom_range(0, 255);
op = $urandom_range(0, 7);
// Apply to interface
T1.a = a;
T1.b = b;
T1.op = op;
opcode_covered[op] = 1'b1;
end
$finish;
end
endmodule
Top module:
// Instantiate the ALU (Design Under Test) using the same interface (uses DUT modport)
alu DUT_inst(I1);
8
// Clock generation: toggles every 5 time units
always #5 clk = ~clk;
endmodule
Simulation output:
9
Coverage report:
10
ASSIGNMENT 3
Implement a 4-bit ALU and develop a randomized test bench with the
following :
ALU Module:
module ALU (
input [3:0] A, // 4-bit input A
input [3:0] B, // 4-bit input B
input [2:0] ALUOp, // ALU Operation selector
output reg [3:0] Result // 4-bit output result
output reg Zero // Zero flag
);
endmodule
Interface module :
interface ALU_if;
// Inputs to ALU
logic [3:0] A, B;
logic [2:0] ALUOp;
11
Transactor class :
class ALU_Transactor;
// Declare the virtual interface
virtual interface ALU_if vif;
Driver class :
class ALU_Driver;
// Declare the virtual interface
virtual interface ALU_if vif;
ALU_Transactor transactor;
Testbench :
module ALU_tb;
12
// Declare the virtual interface
ALU_if alu_if();
// ALU instance
ALU alu_inst (
.A(alu_if.A),
.B(alu_if.B),
.ALUOp(alu_if.ALUOp),
.Result(alu_if.Result),
.Zero(alu_if.Zero)
);
// Driver instance
ALU_Driver driver;
endmodule
13
Simulation output
Coverage report
14