Binary Adders and Subtractors
In questa pagina 7
Binary arithmetic circuits are combinational circuits performing sums, subtractions and other operations on binary numbers. They are the typical iterative circuit: the same sub-function repeats for each bit and identical blocks pass intermediate data (the carries) not appearing in the output. The hierarchical approach is used (Combinational Design - Hierarchy and NAND-NOR MappingA combinational circuit has outputs depending only on the present inputs (no memory, no feedback); a sequential one also depends on history (state, memory, feedback). Design flow: specification, truth table, minimum-cost function, logic diagram, verification. With many inputs the hierarchical approach splits the system into reusable blocks (regularity). Basic blocks: one-variable functions, vectors, enabling. Technology mapping in CMOS: SOP to NAND-NAND, POS to NOR-NOR.Combinational Design - Hierarchy and NAND-NOR Mapping →).
Half adder
The half adder adds two bits and gives the sum (least significant bit of the result) and the carry .
| 0 | 0 | 0 | 0 |
| 0 | 1 | 0 | 1 |
| 1 | 0 | 0 | 1 |
| 1 | 1 | 1 | 0 |
: , , i.e. . It is an XOR plus an AND and has no carry input.
Full adder
The full adder adds three bits: the addends and the carry in from the neighbouring less significant bit.
| 0 | 0 | 0 | 0 | 0 |
| 0 | 0 | 1 | 0 | 1 |
| 0 | 1 | 0 | 0 | 1 |
| 0 | 1 | 1 | 1 | 0 |
| 1 | 0 | 0 | 0 | 1 |
| 1 | 0 | 1 | 1 | 0 |
| 1 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 1 | 1 |
is 1 when the number of 1 inputs is odd (odd-parity function): . is 1 when at least two inputs are 1 (majority): (minimal SOP: 3 prime implicants, all essential).
(); (, ).
Propagate and generate. With (propagate) and (generate): , .
The carry out exists if the two bits generate a carry alone () or propagate the carry in ( and ). So a full adder is: a first half adder , a second half adder and an OR joining and . Equivalence with the majority form: .
Ripple carry adder
To add two -bit numbers and , chain full adders: the carry out of each is the carry in of the next, from the LSB (, usually ) to the MSB (). The carry ripples along the chain.
A3 B3 A2 B2 A1 B1 A0 B0
| | | | | | | |
[ FA3 ]<-C3[ FA2 ]<-C2[ FA1 ]<-C1[ FA0 ]<-C0 (=0 or Cin)
| | | | |
C4 S3 S2 S1 S0():
| bit | (in) | (out) | |||
|---|---|---|---|---|---|
| 0 | 0 | 1 | 0 | 1 | 0 |
| 1 | 1 | 1 | 0 | 0 | 1 |
| 2 | 1 | 1 | 1 | 1 | 1 |
| 3 | 0 | 0 | 1 | 1 | 0 |
Sum , . (): partial sums all and carries : result with , i.e. . For unsigned numbers means overflow (does not fit in 4 bits); for signed numbers the criterion differs (Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →).
A 4-bit adder with carry in has 9 inputs: a truth table of rows is unmanageable, hence the iterative structure.
Delay
Each full adder can compute its sum only when it receives the carry from the previous one: carries are determined one after the other. With gate delay , the carry crosses a stage in about (an AND and an OR), so the total delay grows linearly with : about for the last sum.
With and the last sum arrives after about . The ripple adder is the simplest and slowest; for many bits carry look-ahead circuits are used (not covered in the course).
Subtraction: the adder-subtractor
Two's complement subtraction is (Signed Numbers, Complement Arithmetic and OverflowUnsigned subtraction is correct without borrow out; otherwise the result M-N+2^n is wrong. One's complement is 2^n-1-N (bitwise inversion); two's complement is 2^n-N (one's complement plus 1). Signed numbers: sign-magnitude (two zeros, symmetric range) or two's complement (one zero, range -2^(n-1) to 2^(n-1)-1, MSB weight -2^(n-1)). In two's complement addition and subtraction are the same adder: A-B = A + not B + 1, carry out discarded. Overflow: unsigned if carry out is 1 in an addition; signed if the carry into the sign bit differs from the carry out of it.Signed Numbers, Complement Arithmetic and Overflow →). One circuit does both operations: a control signal ( = add, = subtract). Each bit goes through an XOR with : if it passes , if it passes (one's complement). The same is the carry in of the first full adder, supplying the "+1". The adder computes () or (). For : four XORs and four full adders in cascade.
Overflow: unsigned addition, carry out ; unsigned subtraction, carry out means (correct) and means (result to correct); signed, .
VHDL
entity fa is
port ( x, y, cin : in std_logic;
s, cout : out std_logic );
end fa;
architecture df of fa is
begin
s <= x xor y xor cin;
cout <= (x and y) or (cin and (x xor y));
end df;Structural 4-bit adder (four instances of the full adder, internal carries c):
architecture ripple of add4 is
signal c : std_logic_vector(4 downto 0);
begin
c(0) <= cin;
FA0 : entity work.fa(df) port map (a(0), b(0), c(0), s(0), c(1));
FA1 : entity work.fa(df) port map (a(1), b(1), c(1), s(1), c(2));
FA2 : entity work.fa(df) port map (a(2), b(2), c(2), s(2), c(3));
FA3 : entity work.fa(df) port map (a(3), b(3), c(3), s(3), c(4));
cout <= c(4);
end ripple;Note on the multiplier
As in decimal, the multiplicand is multiplied by each multiplier bit (a product of two bits is an AND), and the partial products are shifted and added. The 2-bit multiplier (, product ) uses 4 ANDs and 2 half adders: Check with : ; with carry ; ; : .
Common mistakes
- Forgetting the carry in of the full adder (a half adder is not enough for middle bits).
- Reading as "wrong result" for signed numbers.
- Believing the ripple adder is fast: delay grows with .
- Swapping (sum bit) and (carry) in the half adder outputs.
Versione ripasso
- Iterative circuit: same sub-function per bit, carries passed along; hierarchical design.
- Half adder: , ; .
- Full adder: , (majority). , .
- Propagate/generate: , , , (two half adders + OR). : .
- Ripple carry, bits: full adders in cascade, or carry in. ; with (): unsigned overflow.
- Table size: 9 inputs, rows: use the iterative structure.
- Delay: about per stage, total (8 bits, 1 ns: 16 ns); linear in .
- Adder-subtractor: XOR of each with , and as carry in: , . Overflow: unsigned ; signed .
- VHDL:
s <= x xor y xor cin;cout <= (x and y) or (cin and (x xor y));structural 4-bit withentity work.fa(df)andc(4 downto 0). - 2-bit multiplier: , , , : 4 ANDs, 2 half adders; .
- Mistakes: carry in forgotten; as signed error; ripple thought fast; and swapped.