Arithmetic Intro Computer Organization 1 Computer Science Dept Va Tech February 2008 © McQuain Algorithm for Integer Division The natural (by-hand) algorithm for integer division is essentially an iterated subtract-and-shift. Recall that mathematics says: or: where:
Arithmetic Intro Computer Organization 2 Computer Science Dept Va Tech February 2008 © McQuain Division Illustrated 15 divided by 6: | ^^^^ 0000 < 0110 no go ^^^ ^ 0001 < 0110 no go ^^ ^^ 0011 < 0110 no go ^ ^^^ 0111 >= 0110 OK, set quotient bit and subtract ^^^^ 0011 < 0110 no go, and done divisor remainder quotient * # negative, retract, shift # negative, retract, shift # negative, retract, shift # OK, keep remainder, shift # negative, retract, shift
Arithmetic Intro Computer Organization 3 Computer Science Dept Va Tech February 2008 © McQuain Division Design 1.0 Divisor Shift right 64-bit ALU 64 bits Remainder Write 64 bits Quotient Shift left Control test 32 bits Look familiar??
Arithmetic Intro Computer Organization 4 Computer Science Dept Va Tech February 2008 © McQuain Division Design 2.0 Just as with multiplication, we can optimize the hardware to eliminate most of the 64-bit components used in the first design. Divisor 32-bit ALU Remainder Write Shift right Control test 32 bits 64 bits Shift left