Experiment # 4 Binary Addition & Subtraction Eng. Waleed Y. Mousa
1. Objectives: 1. To study adder and subtractor circuits using logic gates. 2. To construct and test various adders and subtractor circuits. 2. Theory: Adders: Adder circuit is a combinational digital circuit that is used for adding two numbers. A typical adder circuit produces a sum bit (denoted by S) and a carry bit (denoted by C) as the output. Typically adders are realized for adding binary numbers but they can be also realized for adding other formats like BCD (binary coded decimal), XS-3 etc. Besides addition, adder circuits can be used for a lot of other applications in digital electronics like address decoding, table index calculation etc. Adder circuits are of two types: Half adder ad Full adder. 1. Half Adder: Half adder is a combinational arithmetic circuit that adds two numbers and produces a sum bit (S) and carry bit (C) as the output. If A and B are the input bits, then sum bit (S) is the X-OR of A and B and the carry bit (C) will be the AND of A and B. From this it is clear that a half adder circuit can be easily constructed using one X- OR gate and one AND gate. Half adder is the simplest of all adder circuit, but it has a major disadvantage, the half adder can add only two input bits (A and B) and has nothing to do with the carry if there is any in the input, So if the input to a half adder have a carry, then it will be neglected it and adds only the A and B bits. That means the binary addition process is not complete and that s why it is called a half adder. The truth table, schematic representation and XOR//AND realization of a half adder are shown in the figure below. S = AB'+A'B = AB C = A.B 1
2. Full Adder: Full adder is a logic circuit that adds two input operand bits plus a Carry in bit and outputs a Carry out bit and a sum bit. The Sum out (Sout) of a full adder is the XOR of input operand bits A, B and the Carry in (Cin) bit. Truth table and schematic of a 1 bit Full adder is shown below A Full adder can be made by combining two half adder circuits together (a half adder is a circuit that adds two input bits and outputs a sum bit and a carry bit). S = A'B'Cin + A'BCin' + AB'Cin' + ABCin = A B Cin Cout = ABCin' + AB'Cin+ A'BCin+ ABCin= (A B).Cin + A.B 2
Subtractors: The subtraction of two binary numbers may be accomplished by taking the complement of the subtrahend and adding it to the minuend. By this method, the subtraction operation becomes an addition operation requiring full adders for its machine implementation. It is possible to implement subtraction with logic circuits in a direct manner. By this method, each subtrahend bit of the number is subtracted from its corresponding significant minuend bit to form a different bit. If the minuend bit is smaller than the subtrahend bit, a 1 is borrowed from the next significant position. The fact that a 1 has been borrowed must be conveyed to the next higher pair of bits by means of a binary signal coming out (output) of a given stage and going into (input) the next higher stage. 1. Half Subtractor: The half-subtractor is a combinational circuit which is used to perform subtraction of two bits. It has two inputs, X (minuend) and Y (subtrahend) and two outputs D (difference) and B (borrow). Suppose the minuend bit is x and the subtrahend bit is y. If we want to perform x-y, we have to check the relative magnitude between x and y. If x>=y, we have three possibilities: 0-0=0, 1-0=1 and 1-1=0. The result is known as difference bit. If x<y we have 0-1, and it's necessary to borrow 1 from the next higher stage. The borrowed 1 adds 2 to the minuend bit. With the minuend equal to 2, the difference becomes 2-1=1. The half-subtractor needs two outputs. One is needed to generate the difference and is denoted by the symbol D and the other is needed to show the borrowed bit and is denoted by the symbol B. 3
2. Full Subtractor: The full-subtractor is a combinational circuit which is used to perform subtraction of three bits. It has three inputs, X (minuend) and Y (subtrahend) and Z (subtrahend) and two outputs D (difference) and B (borrow). D=X-Y-Z B = 1 If X<(Y+Z) Inputs Outputs X Y Z D B 0 0 0 0 0 0 0 1 1 1 0 1 0 1 1 0 1 1 0 1 1 0 0 1 0 1 0 1 0 0 1 1 0 0 0 1 1 1 1 1 D = X Y Z. B = X'Y'Z + X'YZ' + X'YZ + XYZ = Z.( X Y)' + X'.Y B = X'Y + X'Z + YZ 4
Parallel Addition: Multiple full adder circuits can be cascaded in parallel to add an N-bit number. For an N- bit parallel adder, there must be N numbers of full adder circuits. A ripple carry adder is a logic circuit in which the carry-out of each full adder is the carry in of the succeeding next most significant full adder. It is called a ripple carry adder because each carry bit gets rippled into the next stage. In a ripple carry adder the sum and carry out bits of any half adder stage is not valid until the carry in of that stage occurs. Note that the first (and only the first) full adder may be replaced by a half adder. Adder-Subtractor: In digital circuits, an adder subtractor is a circuit that is capable of adding or subtracting numbers (in particular, binary). Below is a circuit that does adding or subtracting depending on a control signal. It is also possible to construct a circuit that performs both addition and subtraction at the same time. 5
sel: controller, adding when sel=0 and Subtracting when sel=1. Adding: A+B. Sub: A-B. V: overflow flag, denote that an overflow happened when V=1. 3. Lab Work: Part 1: Construct the circuit of HA using module KL-33004 block a, connect inputs A and B to data switches and outputs F1 (carry) and F2 (sum) to LEDs then find the truth table. Part2: Construct the circuit of FA using module KL-33004 block a, connect inputs A, B and C to data switches and outputs F3 (carry) and F5 (sum) to LEDs then find the truth table. Part3: Construct the circuit of HS and FS using module KL-33004 block a 4. Exercises: 1) Implement the 4-bit Borrow Ripple Subtractor using Full Subtractor. 2) Implement the 4-bit Borrow Ripple Subtractor using Full Adder. 3) Using four half-adders design a four bit combinational circuit incrementer (a circuit that adds 1 to a four bit binary number). 6