Burhan Lab3
Burhan Lab3
Marks Obtain
Group Member 1 Group Member 2
NAME Burhan Akram
REGISTRATION NUMBER 220701050
LAB REPORT
PERFORMANCE
TOTAL MARKS
DATE OF SUBMISSION:
________________________________________________________________________
Experiment # 03 Page 1 of 5
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
The Verilog full subtractor module performs binary subtraction of three input bits (A, B,
and BORROW_IN) and produces a difference (DIFF) and a borrow output (BORROW_OUT).
________________________________________________________________________
Experiment # 03 Page 2 of 5
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
The DIFF is computed using XOR operations: DIFF = (A ^ B) ^ BORROW_IN, ensuring the correct
result for all input combinations. The BORROW_OUT is determined using the formula (~A & B) |
(~A & BORROW_IN) | (B & BORROW_IN), which accounts for all cases where a borrow is
required—when A is 0 and B is 1, when A is 0 and BORROW_IN is 1, or
when B and BORROW_IN are both 1. The module is purely combinational, using continuous
assignments (assign) for logic operations without requiring clock signals, and the timescale 10ns
/ 100ps directive specifies the simulation time unit and precision for accurate timing analysis.
module full_subtractor
(
input A, // Input bit A
input B, // Input bit B
input BORROW_IN, // Borrow input
output DIFF, // Difference output
output BORROW_OUT // Borrow output
);
endmodule
The Verilog testbench (full_subtractor_tb) verifies the functionality of the full subtractor module by
applying all eight possible input combinations (A, B, BORROW_IN) and checking the outputs
(DIFF and BORROW_OUT). It defines the inputs as reg and the outputs as wire, then instantiates the
full subtractor module as uut. Using an initial block, the testbench iterates through all input cases
with a 10ns delay (#10) between each change, while $display prints the results in a structured format
for easy verification. The test concludes with $finish, ensuring proper termination of the simulation.
Below is the testbench code:
module full_subtractor_tb;
.A(A),
.B(B),
.BORROW_IN(BORROW_IN),
.DIFF(DIFF),
.BORROW_OUT(BORROW_OUT)
);
// Test procedure
initial begin
$display("A B BIN | DIFF BOUT");
$display("-----------------");
A = 0; B = 0; BORROW_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 0; B = 1; BORROW_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 0; B = 1; BORROW_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 1; B = 0; BORROW_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 1; B = 0; BORROW_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 1; B = 1; BORROW_IN = 0; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
A = 1; B = 1; BORROW_IN = 1; #10;
$display("%b %b %b | %b %b", A, B, BORROW_IN, DIFF, BORROW_OUT);
endmodule
________________________________________________________________________
Experiment # 03 Page 4 of 5
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Conclusion:
During the exercises, We built a systematic test environment to thoroughly verify the functionality
of the Full Adder and Full Subtractor modules. By applying all possible input combinations and
analyzing the outputs, they gained hands-on experience in verifying digital circuits. This process not
only reinforced their understanding of combinational logic design but also highlighted the
importance of structured testing in ensuring the correctness of hardware implementations. Through
these exercises, students developed essential skills in debugging, simulation, and interpreting
results, which are critical for designing and validating more complex digital systems in the future.
________________________________________________________________________
Experiment # 03 Page 5 of 5
FPGA BASED EMBEDDED SYSTEM DESIGN