CSCI 206 Computer Organization Department of Computer Science

  • Slides: 10
Download presentation
CSCI 206 – Computer Organization Department of Computer Science Bucknell University Integer Division Ch

CSCI 206 – Computer Organization Department of Computer Science Bucknell University Integer Division Ch 3. 4 This set of notes is based on notes from the textbook authors, as well as Alan Marchiori, L. Felipe Perrone, and other instructors. Xiannong Meng, Spring 2021.

Division: Similar to multiplication Algorithm: subtract and shift. . .

Division: Similar to multiplication Algorithm: subtract and shift. . .

Signed Division • Same as signed multiply – divide absolute values – resulting sign

Signed Division • Same as signed multiply – divide absolute values – resulting sign bit: – Quotient and remainder have the same sign

The Divider • Same hardware as multiply! • Setup – divisor in left half

The Divider • Same hardware as multiply! • Setup – divisor in left half of divisor register (64 bit for now) – remainder register initialized with dividend in right half – e. g. , 1001010 would occupy the full 8 -bit 0100 1010

Division Hardware Initially divisor in left half Initially dividend in right half

Division Hardware Initially divisor in left half Initially dividend in right half

0111 / 0010 = ? ? R ? ? Example 1

0111 / 0010 = ? ? R ? ? Example 1

0111 / 0010 = 0011 R 0001 2’s comp of 0010 0000 is 1110

0111 / 0010 = 0011 R 0001 2’s comp of 0010 0000 is 1110 0000 doubled as dividend 2’s comp of 0001 0000 is 1111 0000 2’s comp of 0000 1000 is 1111 1000 2’s comp of 0000 0100 is 1111 1100 2’s comp of 0000 0010 is 1111 1110

Optimized Divider same as optimized multiply hardware Algorithm HI(Remainder) = 0 LO(Remainder) = Dividend

Optimized Divider same as optimized multiply hardware Algorithm HI(Remainder) = 0 LO(Remainder) = Dividend repeat N times: Remainder <<= 1 HI(Remainder) -= Divisor if HI(Remainder) >= 0 Remainder[0] = 1 else HI(Remainder) += Divisor Remainder[0] = 0

Example with optimized divider Iteration Step Divisor Rem/Quotient 0 Initial values 0010 0000 0111

Example with optimized divider Iteration Step Divisor Rem/Quotient 0 Initial values 0010 0000 0111 1 Rem << 1 0010 0000 1110 HI(Rem) -= Div 0010 1110 Rem < 0, Rem+Div, Rem[0] = 0 0010 0000 1110 Rem << 1 0010 0001 1100 HI(Rem) -= Div 0010 1111 1100 Rem < 0, Rem+Div, Rem[0] = 0 0010 0001 1100 Rem << 1 0010 0011 1000 HI(Rem) -= Div 0010 0001 1000 Rem >= 0, Rem[0] = 1 0010 0001 1001 Rem << 1 0010 0011 0010 HI(Rem) -= Div 0010 0001 0010 Rem>=0, Rem[0] = 1 0010 0001 0011 2 3 4 0111 / 0010=0011 R 0001 2’s comp 0010 = 1110 The values in red are quotient, the left part of Rem is the remainder.

Compared with hand-operation in decimal numbers Remainder ______ 23 |10970 _00476_ 23|10970 -092 0177

Compared with hand-operation in decimal numbers Remainder ______ 23 |10970 _00476_ 23|10970 -092 0177 -161 0160 138 22 Quotient Remainder 10970 dividend 00023 divisor 09700 00476 quotient 00010 97000 00022 00010 97000 remainder 00109 70000 00017 70004 00177 00040 00016 00047 00160 00470 Quotient 00022 00476 160 -6*23=22 00000 10970 00001 09700 00001 109 -4*23=17 177 -7*23=16