Arithmetic
Micro-operation |
RTL notation |
description |
Addition |
R3 <– R1 + R2 |
Content of R1 and R2 added, result in R3 |
Subtraction |
R3 <– R1 – R2 |
Content of R2 subtracted from content of R1 added, result in R3 |
1’s complement |
R2 <– R2’ |
Content of R2 complemented |
2’s complement |
R2 <– R2’ +1 |
2’s complement on the Content of R2 |
Subtraction using 2’s complement |
R3 <– R1 + R2’ + 1 |
Subtraction using 2’s complement |
Increment |
R1 <– R1+1 |
An increment micro-operation |
Decrement |
R1 <– R1 – 1 |
A decrement micro-operation |
We now describe the arithmetic circuits for performing the above arithmetic micro-operations. A Half adder and full adders are the basic building blocks used in above operation.
Half Adder:
A half adder is an arithmetic circuit used to add two binary bits. These bits are carry-in and a bit of the number. The symbolic notation of the circuit is shown below:
It finds applications as an incrementer and decrmenter.
Now, RTL is used to generate the circuit from the symbolic code of RTL. For example when the following RTL code is written, the circuit shown in figure … will be generated.
S <= A xor Cin
C <= A and Cin
Now, if the register ‘A’ is assumed to be a 4-bit register, the other input to act as a carry-in to the least significant bit will be equivalent to:
The circuit of Fig-1 can be extended to an n-bit binary incrementer by extending the diagram to include n half-adders. The least significant bit must have one input connected to logic-1. The other inputs receive the number to be incremented or the carry from the previous stage.
Binary Adder
A full adder can be used for implementing the n-bit binary adder. In the following example, two 4-bit numbers A(3-0) and B(3-0) are taken as input to the four full adders. To add the number A and B, Cin input is connected to ground or ‘0’ logic values. The carry out of 1^{st} stage FA is connected as Carry-in to the 2^{nd} stage FA, and carry out of 1^{st} stage FA is connected as Carry-in to the 2^{nd} stage FA, and so on. The carry out of the most significant FA is the final carry out.
S(3-0) = A(3-0) + B(3-0)
C4 is the final carry-out of the most significant FA = A_{3}.B_{3} + (A_{3} xor B_{3}).C_{3}
2’s Complement Adder-Subtracter
The circuit of figure-2 can be expanded to perform 2’s complement addition-subtraction. We use an XOR gate to perform the 2’s complement of a number. The operation is shown in figure-3
The output of the XOR is same as B when M=0, and Y is 1’s complement of B when M=1. We can easily get the 2’s complement of B by adding ‘1’ to its 1’s complement. This logic is incorporated in the binary adder circuit described earlier to get the 2’s complement adder-subtracter circuit shown in figure-3
When M=0, the B input is passed directly as one of the input to the FA and also the carry-in which is same as M is zero (‘0’). The output thus obtained will be the binary addition of A and B.
Binary subtraction: When M=1, XOR performs the 1’s complement of B and also the Carry-in, which is same as M becomes ‘1’. This results in subtraction using 2’s complement arithmetic. The operation is S= A + B’ +1
Arithmetic Unit
All the operations discussed above can be implemented in a single composite circuit shown in figure-5. The circuit uses four FA. One of the input A is connected directly to one input of FA, the 2^{nd} input is connected though the MUX. By controlling the data inputs to the adder, it is possible to obtain different types of arithmetic operations.
The circuit uses four 4×1 MUXes. The sources can be controlled by using the control signal to the MUX. Table describes the source for input Y of the FA and the output function (‘D’).
Operation | S1 | S0 | Cin | Y | Output ‘D’ | microoperation |
Addition | 0 | 0 | 0 | B | D= A+B | With SS_{0}=00, input ‘B’ is applied as input to FA. When Cin=0, operation as D= A+B+0. i.e add without carry |
0 | 0 | 1 | B | D=A+B+1 | With S_{1}S_{0}=00, input ‘B’ is applied as input to FA. When Cin=1, operation performed is add with carry i.e D= A+B+1 | |
Subtract | 0 | 1 | 0 | B’ | D=A+B’ | With S_{1}S_{0}=00, input B’ is applied as input to FA. When Cin=0, operation as D= A+B’+0. i.e. Subtract with borrow |
0 | 1 | 1 | B’ | D=A+B’+1 | With S_{1}S_{0}=00, input B’ is applied as input to FA. When Cin=0, operation as D= A+B’+1. i.e. Subtract with Subtraction using 2’s complement | |
Transfer | 1 | 0 | 0 | ‘0’ | D=A+0
= A |
When S_{1}S_{0} = 10, the inputs from B are neglected, and instead, all O’s are inserted into the Y inputs. The output becomes D = A + 0 + Cin· This gives D = A . This is Transfer operation at output, |
Increment/ Decrement | 1 | 0 | 1 | ‘0’ | D=A+0+1 | When S_{1}S_{0} = 10, the inputs from B are neglected, and instead, all O’s are inserted into the Y inputs. The output becomes D = A + 0 + Cin· This gives D = A when Cm = 0 and D = A + 1 when Cin = 1. In the first case we have a direct transfer from input A to output D. In the second case, the value of A is incremented by 1. |
1 | 1 | 0 | 1 | D=A-1 | When S1So = 11, all 1′ s are inserted into the Y inputs of the adder to produce the decrement operation D = A – 1 when Cm = 0. This is because a number with all 1’s is equal to the 2’s complement of 1 (the 2’s complement of binary 0001 is 1111). Adding a number A to the 2’s complement of 1 produces F =A + 2’s complement of 1 = A – 1. Which is a Decrement operation | |
Transfer | 1 | 1 | 1 | 1 | D=A-1+1 | When Cin = 1, then D =A – 1 + 1 = A, this is a simple transfer of input A at output. i.e. D=A |