1 / 11

Lecture 15: Computer Arithmetic

Lecture 15: Computer Arithmetic. Today’s topic Division. Division. Check for 0 divisor Long division approach If divisor ≤ dividend bits 1 bit in quotient, subtract Otherwise 0 bit in quotient, bring down next dividend bit Restoring division Always performs subtract first

Download Presentation

Lecture 15: Computer Arithmetic

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Lecture 15: Computer Arithmetic • Today’s topic • Division

  2. Division • Check for 0 divisor • Long division approach • If divisor ≤ dividend bits • 1 bit in quotient, subtract • Otherwise • 0 bit in quotient, bring down next dividend bit • Restoring division • Always performs subtract first • Do the subtract, and if remainder goes < 0, add divisor back • Signed division • Divide using absolute values • Adjust sign of quotient and remainder as required quotient dividend 1001 1000 1001010 -1000 10 101 1010 -1000 10 divisor remainder n-bit operands yield n-bitquotient and remainder

  3. Division 1001tenQuotient Divisor 1000ten | 1001010tenDividend 0001001010 0001001010 0000001010 0000001010 100000000000  0001000000 00001000000000001000 Quo: 0 000001 0000010 000001001 • At every step, • shift divisor right and compare it with current dividend • if divisor is larger, shift 0 as the next bit of the quotient • if divisor is smaller, subtract to get new dividend and shift 1 • as the next bit of the quotient

  4. Division Hardware Initially divisor in left half Initially dividend

  5. Divide Example • Divide 7ten (0000 0111two) by 2ten (0010two)

  6. Divide Example • Divide 7ten (0000 0111two) by 2ten (0010two)

  7. Optimized Divider • One cycle per partial-remainder subtraction • Looks a lot like a multiplier! • Same hardware can be used for both

  8. Faster Division • Can’t use parallel hardware as in multiplier • Subtraction is conditional on sign of remainder • Faster dividers (e.g. SRT devision) generate multiple quotient bits per step • Still require multiple steps

  9. MIPS Division • Use HI/LO registers for result • HI: 32-bit remainder • LO: 32-bit quotient • Instructions • div rs, rt / divu rs, rt • No overflow or divide-by-0 checking • Software must perform checks if required • Use mfhi, mflo to access result

  10. Divisions involving Negatives • Simplest solution: convert to positive and adjust sign later • Note that multiple solutions exist for the equation: • Dividend = Quotient x Divisor + Remainder • +7 div +2 Quo = Rem = • -7 div +2 Quo = Rem = • +7 div -2 Quo = Rem = • -7 div -2 Quo = Rem =

  11. Divisions involving Negatives • Simplest solution: convert to positive and adjust sign later • Note that multiple solutions exist for the equation: • Dividend = Quotient x Divisor + Remainder • +7 div +2 Quo = +3 Rem = +1 • -7 div +2 Quo = -3 Rem = -1 • +7 div -2 Quo = -3 Rem = +1 • -7 div -2 Quo = +3 Rem = -1 • Convention: Dividend and remainder have the same sign • Quotient is negative if signs (of dividend and divisor) disagree • These rules fulfil the equation above

More Related