Unformatted text preview:

Chapter 3: Arithmetic3-1CPSC 352Chapter 3: ArithmeticChapter 3: Arithmetic3-2Chapter Contents3.1 Overview3.2 Fixed Point Addition and Subtraction3.3 Fixed Point Multiplication and Division3.4 Floating Point Arithmetic3.5 High Performance Arithmetic3.6 Case Study: Calculator Arithmetic Using Binary Coded DecimalChapter 3: Arithmetic3-3Computer Arithmetic•Using number representations from Chapter 2, we will explore fourbasic arithmetic operations: addition, subtraction, multiplication,division.• Significant issues include: fixed point vs. floating point arithmetic,overflow and underflow, handling of signed numbers, and perfor-mance.• We look first at fixed point arithmetic, and then at floating pointarithmetic.Chapter 3: Arithmetic3-4 Number Circle for 3-Bit Two’sComplement Numbers•Numbers can be added or subtracted by traversing the numbercircle clockwise for addition and counterclockwise for subtraction.• Overflow occurs when a transition is made from +3 to -4 while pro-ceeding around the number circle when adding, or from -4 to +3while subtracting.100010110000111101 0110010123-4-3-2-1AddingnumbersSubtractingnumbersChapter 3: Arithmetic3-5Overflow•Overflow occurs when adding two positive numbers produces anegative result, or when adding two negative numbers produces apositive result. Adding operands of unlike signs never produces anoverflow.• Notice that discarding the carry out of the most significant bit dur-ing two’s complement addition is a normal occurrence, and doesnot by itself indicate overflow.• As an example of overflow, consider adding (80 + 80 = 160)10, whichproduces a result of -9610 in an 8-bit two’s complement format: 01010000 = 80+ 01010000 = 80---------- 10100000 = -96 (not 160 because the sign bit is 1.)Chapter 3: Arithmetic3-6Ripple Carry Adder•Two binary numbers A and B are added from right to left, creatinga sum and a carry at the outputs of each full adder for each bit po-sition.Fulladderb0a0s0Fulladderb1a1s1Fulladderb2a2s2Fulladderb3a3c4s30c0c1c2c3Chapter 3: Arithmetic3-7Constructing Larger Adders•A 16-bit adder can be made up of a cascade of four 4-bit ripple-carry adders.s0b1a1s1b2a2s2b3a3c4s304-Bit Adder #0b0a0s12b13a13s13b14a14s14b15a15c16s154-Bit Adder #3b12a12. . .c12c0Chapter 3: Arithmetic3-8Full Subtractor•Truth table and schematic symbol for a ripple-borrow subtractor:0011001101010101bibori00001111ai01101001diffi01110001bori+1Fullsub-tractorbiaiboribori+1diffi(ai – bi)Chapter 3: Arithmetic3-9 Ripple-Borrow Subtractor•A ripple-borrow subtractor can be composed of a cascade of fullsubtractors.•Two binary numbers A and B are subtracted from right to left, cre-ating a difference and a borrow at the outputs of each fullsubtractor for each bit position.b0a0diff0b1a1diff1b2a2diff2Fullsub-tractorb3a3bor4diff30Fullsub-tractorFullsub-tractorFullsub-tractorbor0Chapter 3: Arithmetic3-10 Combined Adder/SubtractorFulladderb0a0s0Fulladderb1a1s1Fulladderb2a2s2Fulladderb3a3c4s3c0ADD /SUBTRACT•A single ripple-carry adder can perform both addition and subtrac-tion, by forming the two’s complement negative for B when sub-tracting. (Note that +1 is added at c0 for two’s complement.)Chapter 3: Arithmetic3-11 One’s Complement Addition•An example of one’s complement integer addition with an end-around carry: +1100010010100110(–12)10(+13)10+ 0 0 0 011(+1)10End-around carry•The end-around carry is needed because there are two represen-tations for 0 in one’s complement. Both representations for 0 arevisited when one or both operands are negative.Chapter 3: Arithmetic3-12 Number Circle (Revisited)•Number circle for a three-bit signed one’s complement represen-tation. Notice the two representations for 0.100010110000111101 011001+0123-3-2-1-0AddingnumbersSubtractingnumbersChapter 3: Arithmetic3-13 End-Around Carry for Fractions•The end-around carry complicates one’s complement addition fornon-integers, and is generally not used for this situation.•The issue is that the distance between the two representations of0 is 1.0, whereas the rightmost fraction position is less than 1. 1010110011101...(+5.5)10(–1.0)10 + (+4.5)10101 + 0 1 010..01Chapter 3: Arithmetic3-14 Multiplication Example•Multiplication of two 4-bit unsigned binary integers produces an8-bit result.11011011×110111010000110110001111(11)10(13)10Multiplicand MMultiplier Q(143)10Product PPartial products•Multiplication of two 4-bit signed binary integers produces only a7-bit result (each operand reduces to a sign bit and a 3-bit mag-nitude for each operand, producing a sign-bit and a 6-bit result).Chapter 3: Arithmetic3-15 A Serial MultiplierMultiplicand (M)m0m1m2m3a0a1a2a3q0q1q2q3Multiplier (Q)C4–Bit AdderShift and Add Control LogicAdd444Shift Rightq0A RegisterChapter 3: Arithmetic3-16 Example of Multiplication UsingSerial MultiplierC000100100A00011010110001110010100000110001Q0111011110111011110111111111111Multiplicand (M):1101Initial valuesAdd M to AShiftAdd M to AShiftShift (no add)Add M to AShiftProductChapter 3: Arithmetic3-17 Example of Base 2 Division1100100111110R11•(7 / 3 = 2)10 with a remainder R of 1.•Equivalently, (0111/ 11 = 10)2 with a remainder R of 1.Chapter 3: Arithmetic3-18 Serial DividerDivisor (M)m0m1m2m3a0a1a2a3q0q1q2q3Dividend (Q)5–Bit AdderShift andAdd / Sub Control LogicAdd / Sub555Shift Leftq0A Registera40a4Chapter 3: Arithmetic3-19 Division Example Using Serial Divider001000A00000001101001100000Q1111110111010001000Divisor (M):0011Initial valuesShift leftSubtract M from AShift leftSubtract M from A00000 1110 Restore A (Add M to A)010001111011001100Shift leftSubtract M from A00001 1100 Restore A00000 1110 Clear q000001 1100 Clear q000000 1001 Set q0010001111000100010Shift leftSubtract M from A00001 0010 Restore A00001 0010 Clear q0Remainder Quotient0Chapter 3: Arithmetic3-20 Multiplication of Signed Integers11110001×111100000000000000001111(+1)10(–1)10(+15)10(Incorrect; result should be –1)11110001×111100000000000011111111(+1)10(–1)10(–1)1011111111000000•Sign extension to the target word size is needed for the negativeoperand(s).•A target word size of 8 bits is used here for two 4-bit signed op-erands, but only a 7-bit target word size is needed for the result.Chapter 3: Arithmetic3-21 Carry-Lookahead AdditionGi = aibi and Pi = ai + bic0 = 0c1 = G0c2 = G1 + P1G0c3 = G2 + P2G1 + P2P1G0c4 = G3 + P3G2 + P3P2G1 + P3P2P1G0•Carries are represented in termsof Gi


View Full Document

Radford ITEC 352 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?