27_lab 04 fpga
27_lab 04 fpga
Marks Obtain
Group Member 1 Group Member 2
NAME M.Diyan Zahid
REGISTRATION NUMBER 220701027
LAB REPORT 04
PERFORMANCE
TOTAL MARKS
DATE OF SUBMISSION:
________________________________________________________________________
Experiment # 04 Page 1 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Objectives:
The primary objective of this lab is to designing a 4-Bit Ripple Carry Full Adder
through instantiating individual 1-Bit Full Adders within the 4-Bit module.
The students will gain a deep understanding of how to structure and interconnect
modules using instantiation techniques.
Introduction:
A N-bit full adder can be designed by cascading N number of 1-bit full adders. Each full
adder takes a carry-in Cin, which is the carry-out Cout of the previous adder. This kind of
chain of adders forms a ripple-carry adder, since each carry-bit "ripples" to the next full
adder. The layout of a ripple-carry adder is simple, which allows for fast design time;
however, the ripple-carry adder is relatively slow, since each full adder must wait for the
carry-bit to be calculated from the previous full adder. A 4-bit ripple carry adder formed
by cascading four 1-bit full adders is shown in Figure 1.
Figure 1. 4-bit Carry Ripple Adder formed by cascading four full adders
________________________________________________________________________
Experiment # 04 Page 2 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Verilog Module
Figure 2 shows the Verilog module of a 4-bit carry ripple adder. A and B are the two 4-
bit input ports which is used to read in the two 4-bit numbers that are to be summed up.
The 1-bit carry-in input port Cin is used to read in a carry bit, if another instance of the
ripple carry adder is cascaded towards lesser significant stage. The 4-bit sum generated
by the adder is presented in the 4-bit output port Sum and 1-bit carry-out in the Cout
output port. The carry out, Cout provides a carry-bit, if another instance of the ripple
carry adder is cascaded towards more significant stage.
module ripple_carry_4bit_full_adder(
input [3:0] A, B, // 4-bit inputs
input Cin, // Carry input
output [3:0] Sum, // 4-bit sum output
output Cout // Carry output
);
wire [3:0] c; // Internal carry signals
endmodule
// 1-bit full adder module
module full_adder (
input A, B, Cin,
________________________________________________________________________
Experiment # 04 Page 3 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Test Bench
// Test case 2
A = 4'b1101; // Binary 13
B = 4'b0010; // Binary 2
Cin = 1;
#10;
________________________________________________________________________
Experiment # 04 Page 4 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
$display("Test Case 2: A = %b, B = %b, Cin = %b, Sum = %b, Cout = %b", A, B, Cin,
Sum, Cout);
// End simulation
$finish;
end
endmodule
Time diagram
Task:
Design 4-Bit Full subtractor by instantiating 1-Bit subtractor
________________________________________________________________________
Experiment # 04 Page 5 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
A 4-bit ripple carry subtractor performs bitwise subtraction of two 4-bit numbers using
full subtractors.Each 1-bit full subtractor computes the difference and propagates the
borrow to the next stage.The borrow output (Bout) of one stage acts as the borrow input
(Bin) for the next stage.The difference is computed as A + B + Bin, and borrow is
determined using (~A & (B | Bin)) | (B & Bin).This design ensures sequential borrow
propagation, similar to a ripple carry adder but for subtraction.
Verilog:
________________________________________________________________________
Experiment # 04 Page 6 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Testbench:
________________________________________________________________________
Experiment # 04 Page 7 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN
_________________________________________________________________________
Timing Diagram:
Conclusion:
In the first case, a borrow is generated since A is smaller than B.In the second case, no
borrow is needed because A is larger than B.The ripple carry subtractor correctly
computes the difference and propagates borrow if required.
________________________________________________________________________
Experiment # 04 Page 8 of 8
FPGA BASED EMBEDDED SYSTEM DESIGN