02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the...

24
9/6/2011 1 Multiplication Binary Multipliers × 0 1 2 3 4 5 6 7 8 9 0 0 0 0 0 0 0 0 0 0 0 1 0 1 2 3 4 5 6 7 8 9 2 0 2 4 6 8 10 10 10 10 12 12 12 12 14 14 14 14 16 16 16 16 18 18 18 18 3 0 3 6 9 12 12 12 12 15 15 15 15 18 18 18 18 21 21 21 21 24 24 24 24 27 27 27 27 4 0 4 8 12 12 12 12 16 16 16 16 20 20 20 20 24 24 24 24 28 28 28 28 32 32 32 32 36 36 36 36 5 0 5 10 10 10 10 15 15 15 15 20 20 20 20 25 25 25 25 30 30 30 30 35 35 35 35 40 40 40 40 45 45 45 45 6 0 6 12 12 12 12 18 18 18 18 24 24 24 24 30 30 30 30 36 36 36 36 42 42 42 42 48 48 48 48 54 54 54 54 7 0 7 14 14 14 14 21 21 21 21 28 28 28 28 35 35 35 35 42 42 42 42 49 49 49 49 56 56 56 56 63 63 63 63 8 0 8 16 16 16 16 24 24 24 24 32 32 32 32 40 40 40 40 48 48 48 48 56 56 56 56 64 64 64 64 72 72 72 72 9 0 9 18 18 18 18 27 27 27 27 36 36 36 36 45 45 45 45 54 54 54 54 63 63 63 63 72 72 72 72 81 81 81 81 × 0 1 0 0 0 1 0 1 The key trick of multiplication is memorizing a digit-to-digit table Everything else was just adding

Transcript of 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the...

Page 1: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

1

Multiplication

Binary Multipliers

×0000 1111 2222 3333 4444 5555 6666 7777 8888 9999

0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

1111 0000 1111 2222 3333 4444 5555 6666 7777 8888 9999

2222 0000 2222 4444 6666 8888 10101010 12121212 14141414 16161616 18181818

3333 0000 3333 6666 9999 12121212 15151515 18181818 21212121 24242424 27272727

4444 0000 4444 8888 12121212 16161616 20202020 24242424 28282828 32323232 36363636

5555 0000 5555 10101010 15151515 20202020 25252525 30303030 35353535 40404040 45454545

6666 0000 6666 12121212 18181818 24242424 30303030 36363636 42424242 48484848 54545454

7777 0000 7777 14141414 21212121 28282828 35353535 42424242 49494949 56565656 63636363

8888 0000 8888 16161616 24242424 32323232 40404040 48484848 56565656 64646464 72727272

9999 0000 9999 18181818 27272727 36363636 45454545 54545454 63636363 72727272 81818181

×0000 1111

0000 0000 0000

1111 0000 1111

The key trick of multiplication is memorizing a digit-to-digit table�

Everything else was just adding

Page 2: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

2

– Multiplication can be performed as a sequence of

repeated additions.

– A * B is interpreted as add A, B times. However,

such a scheme is very inefficient with a time

complexity of O(m) where m is the magnitude of B.

– A better approach to multiplication, add-and-shift, produces a time complexity of O(n) where n is the length of the B.

Multiplication

Binary Multiplication

A0A1A2A3

B0B1B2B3

A0B0A1B0A2B0A3B0

A0B1A1B1A2B1A3B1

A0B2A1B2A2B2A3B2

A0B3A1B3A2B3A3B3

x

+

AjBi is a “partial product”

Multiplying N-digit number by M-digit number gives (N+M)-digit result

Easy part: forming partial products (just an AND gate since BI is either 0 or 1)

Hard part: adding M, N-bit partial products

101

000

10X

The “Binary”

Multiplication

Table

that looks

like an AND

gate

Binary multiplication is implemented

using the same basic longhand algorithm

that you learned in grade school.

Page 3: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

3

Combinational Multiplier: accumulation of partial products

A0

B0

A0 B0

A1

B1

A1 B0

A0 B1

A2

B2

A2 B0

A1 B1

A0 B2

A3

B3

A2 B0

A2 B1

A1 B2

A0 B3

A3 B1

A2 B2

A1 B3

A3 B2

A2 B3A3 B3

S6 S5 S4 S3 S2 S1 S0S7

• Paper and Pencil Example:

Multiplicand 11002 = 12Multiplier × 11012 = 13

11000000

11001100

Product 100111002 = 156

• m-bit multiplicand × n-bit multiplier = (m+n)-bit product

• Accomplished via shifting and addition

Unsigned Multiplication

Binary multiplication is easy

0 × multiplicand = 0

1 × multiplicand = multiplicand

Page 4: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

4

Multiplication of unsigned numbers

Product of 2 n-bit numbers is at most a 2n-bit number.

Unsigned multiplication can be viewed as addition of shifted

versions of the multiplicand.

Array Multiplier: Carry Forward

y3 y2 y1 y0 Multiplicand

x3 x2 x1 x0 Multiplier

________________________

x0y3 x0y2 x0y1 x0y0

x1y3 x1y2 x1y1 x1y0 Partial

x2y3 x2y2 x2y1 x2y0 Products

x3y3 x3y2 x3y1 x3y0

__________________________________________________

p7 p6 p5 p4 p3 p2 p1 p0

Note: Carry is added to the next partial product. Adding the carry

from the final stage needs an extra stage. These additions are

faster but we need four stages.

Page 5: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

5

Array Multiplier: Carry Forward

y3 y2 y1 y0 Multiplicand

x3 x2 x1 x0 Multiplier

________________________

x0y3 x0y2 x0y1 x0y0

x1y3 x1y2 x1y1 x1y0 Partial

x2y3 x2y2 x2y1 x2y0 Products

x3y3 x3y2 x3y1 x3y0

__________________________________________________

p7 p6 p5 p4 p3 p2 p1 p0

Note: Carry is added to the next partial product. Adding the carry

from the final stage needs an extra stage. These additions are

faster but we need four stages.

Basic Building Blocks

• Two-input AND

• Full-adder

Fulladder

yi x0

p0i = x0yi

0th partial product(k+1)th partialproduct

kthpartialproduct

Bi xk

carry bitsfrom (k-1)thproduct

carry bitsto (k+1)thproduct

Page 6: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

6

Multiplication of unsigned numbers

ith multiplier bit

carry incarry out

jth multiplicand bit

ith multiplier bit

Bit of incoming partial product (PPi)

Bit of outgoing partial product (PP(i+1))

FA

Typical multiplication cell

AjBi

A3 B0

SC

A2 B0

SC

A1 B0

SC

A0 B0

SC

A3 B1

SC

A2 B1

SC

A1 B1

SC

A0 B1

SC

A3 B2

SC

A2 B2

SC

A1 B2

SC

A0 B2

SC

A3 B3

SC

A2 B3

S

A1 B3

S

A0 B3

S

B0

B1

B2

B3

P7 P6 P5 P4 P3 P2 P1 P0

A3 A2 A1 A0

M U L T I P L I C A N D

M

U

L

T

I

P

L

I

E

R

Page 7: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

7

Combinatorial array multiplier

Multiplicand

m3 m2 m1 m00 0 0 0

q3

q2

q1

q00

p2

p1

p0

0

0

0

p3p4p5p6p7

PP1

PP2

PP3

(PP0)

,

Product is: p7,p6,..p0

Multiplicand is shifted by displacing it through an array of adders.

Combinatorial array multiplier

Combinatorial array multiplier (contd..)

• Combinatorial array multipliers are:– Extremely inefficient.

– Have a high gate count for multiplying numbers of practical size such as 32-bit

or 64-bit numbers.

– Perform only one function, namely, unsigned integer product.

• Improve gate efficiency by using a mixture of combinatorial

array techniques and sequential techniques requiring less

combinational logic.

Page 8: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

8

• Add-and-shift — Algorithm

– In each iteration the least-significant bit of multiplier is

checked;

• if one, then multiplicand is added to the accumulator and the

contents of accumulator and multiplier is shifted right one

position.

• if zero, just shift accumulator and multiplier to the right.

Sequential Circuit Multiplier

qn 1-

mn 1-

n-bit

Adder

Multiplicand

M

Controlsequencer

Multiplier Q

0

C

Shift right

Register A (initially 0)

Add/Noaddcontrol

an 1-

a0

q0

m0

0

MUX

Control Algorithm:

1. A ← 0, M ← multiplicand,

Q ← multiplier

2. If LSB of Q==1 then add M to A

else add 0

3. Shift [A][Q] right 1

4. Repeat steps 2 and 3 n-1 times.

5. [A][Q] has product.

Page 9: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

9

Sequential multiplication (contd..)

1 1 1 1

1 0 1 1

1 1 1 1

1 1 1 0

1 1 1 0

1 1 0 1

1 1 0 1

Initial configuration

Add

M

1 1 0 1

C

First cycle

Second cycle

Third cycle

Fourth cycle

No add

Shift

ShiftAdd

Shift

ShiftAdd

1 1 1 1

0

0

0

1

0

0

0

1

0

0 0 0 0

0 1 1 0

1 1 0 1

0 0 1 1

1 0 0 1

0 1 0 0

0 0 0 1

1 0 0 0

1 0 0 1

1 0 1 1

QA

Product

Control Algorithm:

1. A ← 0, M ← multiplicand,

Q ← multiplier

2. If LSB of Q==1 then add M to A

else add 0

3. Shift [A][Q] right 1

4. Repeat steps 2 and 3 n-1 times.

5. [A][Q] has product.

Signed Multiplication

Page 10: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

10

Signed Multiplication

• Considering 2’s-complement signed operands, what will happen to (-

13)×(+11) if following the same method of unsigned multiplication?

Sign extension of negative multiplicand.

1

0

11 11 1 1 0 0 1 1

110

110

1

0

1000111011

000000

1100111

00000000

110011111

13-( )

143-( )

11+( )

Sign extension isshown in blue

Signed multiplication

multiplicand

multiplier

1101 (-3)

1011 (-5)

1101

11010

000000

1101000

*

(15)

1111 Note: 2s complement

Sign extension111

00

1

+(-3)+

+

+

-

+(-6)

-(-24)

00001111

Page 11: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

11

Signed Multiplication (Pencil & Paper)

• Case 1: Positive MultiplierMultiplicand 11002 = -4

Multiplier × 01012 = +5

11111100

111100

Product 111011002 = -20

• Case 2: Negative MultiplierMultiplicand 11002 = -4

Multiplier × 11012 = -3

11111100

111100

00100 (2's complement of 1100)

Product 000011002 = +12

Sign-extension

Sign-extension

• Consider decimal multiplication:

4 5 7

9 9 9 0 1

4 5 7

4 1 1 3

4 1 1 3

4 1 1 3

4 5 6 5 4 7 5 7

Page 12: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

12

What is the Trick?

• Examine multiplier:

99901 = 100000 – 100 + 1

• Multiply as follows:

457 × 100000 = 45700000

457 × ( - 100) = - 45700

45654300

457 × 1 = 457

45654757

Booth Algorithm: Basic Idea• Consider a multiplier, 00011110 (30)

• We can write, 30 = 32 – 2, or

00100000 (32) = 25

+11111110 (–2) = –21

00011110(0) 30

• Interpret multiplier (scan right to left), check bit-pairs:

• Product, M×30 = M×25 - M×21 M: multiplicand

• Multiplication by 2k means a k-bit left shift

Page 13: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

13

Booth Algorithm

• In general, in the Booth scheme, -1 times the shifted multiplicand is selected when moving from 0 to 1, and +1 times the shifted multiplicand is selected when moving from 1 to 0, as the multiplier is scanned from right to left.

Booth recoding of a multiplier.

001101011100110100

00000000 1+ 1-1-1+1-1+1-1+1-1+

(0)

Booth Algorithm

Booth multiplication with a negative multiplier.

01

0

1 1 1 1 0 1 1

0 0 0 0 0 0 0 0 0

00

0110

0 0 0 0 1 1 0

1100111

0 0 0 0 0 0

01000 11111

1

10 1 1 0 1

1 1 0 1 0 6-( )

13+( )

X

78-( )

+11- 1-

Page 14: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

14

Booth Algorithm

Multiplier

Bit i Bit i 1-

Version of multiplicandselected by biti

0

1

0

0

01

1 1

0 M

1+ M

1− M

0 M

Booth multiplier recoding table.

X

X

X

X

Booth Algorithm

• Best case – a long string of 1’s (skipping over 1s)

• Worst case – 0’s and 1’s are alternating

1

0

1110000111110000

001111011010001

1 0 1 0 1 0 1 0 1 0 1 0 1 0 1

0

000000000000

00000000

1- 1- 1- 1- 1- 1- 1- 1-

1- 1- 1- 1-

1-1-

1+ 1+ 1+ 1+ 1+ 1+ 1+ 1+

1+

1+1+1+

1+

Worst-case

multiplier

Ordinarymultiplier

Goodmultiplier

Page 15: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

15

Booth Algorithm: Example 1

• 7 × 3 = 21

0111 multiplicand = 7

×0011(0) multiplier = 3

11111001 bit-pair 10, add -7 in two’s com.

bit-pair 11, do nothing

000111 bit-pair 01, add 7

bit-pair 00, do nothing

00010101 21

Booth Algorithm: Example 2

• 7 × (-3) = -21

0111 multiplicand = 7

×1101(0) multiplier = -3

11111001 bit-pair 10, add -7 in two’s com.

0000111 bit-pair 01, add 7

111001 bit-pair 10, add -7 in two’s com.

bit-pair 11, do nothing

11101011 - 21

Page 16: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

16

Booth Algorithm: Example 3

• -7 × 3 = -21

1001 multiplicand = -7 in two’s com.

×0011(0) multiplier = 3

00000111 bit-pair 10, add 7

bit-pair 11, do nothing

111001 bit-pair 01, add -7

bit-pair 00, do nothing

11101011 - 21

Booth Algorithm: Example 4

• -7 × (-3) = 21

1001 multiplicand = -7 in two’s com.

×1101(0) multiplier = -3 in two’s com.

00000111 bit-pair 10, add 7

1111001 bit-pair 01, add -7 in two’s com.

000111 bit-pair 10, add 7

bit-pair 11, do nothing

00010101 21

Page 17: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

17

Booth Advantage

00010100 20

×00011110 30

00000000

00010100

00010100

00010100

00010100

00000000

00000000

00000000________

000001001011000 600

00010100 20

×000111100 30

111111111101100

00000010100

__________________

0000001001011000 600

Serial multiplication Booth algorithm

Four partial product additions Two partial product additions

Fast Multiplication

Page 18: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

18

Bit-Pair Recoding of Multipliers

• Bit-pair recoding halves the maximum number of summands

(versions of the multiplicand).

1+1−

(a) Example of bit-pair recoding derived from Booth recoding

0

000

1 1 0 1 0

Implied 0 to right of LSB

1

0

Sign extension

1

21− −

Bit-Pair Recoding of Multipliers

i 1+ i 1

(b) Table of multiplicand selection decisions

selected at position i

MultiplicandMultiplier bit-pair

i

0

0

1

1

1

0

1

0

1

1

1

1

0

0

0

1

1

0

0

1

0

0

1

Multiplier bit on the right

0 0 X M

1+

1

1+

0

1

2

2+

X M

X M

X M

X M

X M

X M

X M

Page 19: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

19

Bit-Pair Recoding of Multipliers

1-

0000

1 1 1 1 1 0

0 0 0 0 11

1 1 1 1 10 0

0 0 0 0 0 0

0000 111111

0 1 1 0 1

0

1 010011111

1 1 1 1 0 0 1 1

0 0 0 0 0 0

1 1 1 0 1 1 0 0 1 0

0

1

0 0

1 0

1

0 0

0

0 1

0

0 1

10

0

010

0 1 1 0 1

11

1-

6-( )

13+( )

1+

78-( )

1- 2-

´

Figure : Multiplication requiring only n/2 summands.

i 1+ i 1selected at position i

MultiplicandMultiplier bit-pair

i

0

0

1

1

1

0

1

0

1

1

1

1

0

0

0

1

1

0

0

1

0

0

1

Multiplier bit on the right

0 0 X M

1+

1

1+

0

1

2

2+

X M

X M

X M

X M

X M

X M

X M

Integer Division

Page 20: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

20

– Similar to multiplication, one can develop a routine to perform division

as a sequence of subtractions.

– However, such an algorithm is very inefficient and slow.

– Instead one can develop an algorithm which performs division as a

sequence of Compare, Shift and Subtract operations.

Division

– One should note that division in a binary system is much simpler than the

division in decimal system, since the quotient digits are either 0 or 1.

– In other words; division requires almost the same hardware modules as

multiplication does.

Methods of Division

• There are several different algorithms for division:

– Restoring Method

– Non-Restoring Method

– Direct Comparison

Page 21: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

21

– In the restoring method, the contents of the partial remainder is

restored whenever it is detected that the divisor is larger than the

partial remainder.

restoring method

– In non-restoring method, if it is detected that the divisor is larger

than the partial remainder, its contents are not restored.

– However, in the next iteration, instead of subtracting the divisor

from the partial remainder, it is added to the partial remainder.

non-restoring method

In direct comparison approach, first the divisor is compared against the

partial remainder.

• If it is smaller than or equal to the partial remainder, it will be

subtracted and quotient digit is set to 1.

• Otherwise, just the quotient is set to zero.

direct comparison or Longhand division

Manual Division

Longhand division examples.

1101

1

13

14

26

21

274 100010010

10101

1101

1

1110

1101

10000

13 1101

Page 22: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

22

= 19 Quotient

Divisor 10112 110110012 = 217 Dividend-1011

10101101010100-1011

100110011-1011

10002 = 8 Remainder

Unsigned Division (Paper & Pencil)

Binary division is

accomplished via

shifting and subtraction

Dividend =

Quotient × Divisor

+ Remainder

217 = 19 × 11 + 8

100112

Circuit Arrangement

Figure : Circuit arrangement for binary division.

qn-1

Divisor M

Control

Sequencer

Dividend Q

Shift left

N+1 bit

adder

q0

Add/Subtract

Quotient

Setting

A

m00 mn-1

a0an an-1

Page 23: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

23

Restoring Division

• Shift A and Q left one binary position

• Subtract M from A, and place the answer back in A

• If the sign of A is 1, set q0 to 0 and add M back to A (restore A); otherwise,

set q0 to 1

• Repeat these steps n times

1. A�0, Q� Dividend, M� Divisor

2. Shift left AQ by one position

3. A�A-M

4. If sign of A is 1

q0 �0

A�A+M

Else

q0�1

5. Repeat step 2 to 4 for n-1 times

Pseudo code is:

Examples

10111

Figure : A restoring-division example.

1 1 1 1 1

01111

0

0

0

1

000

0

0

00

0

0

0

00

0

1

00

0

0

0

1 01

11

1 1

01

0001

SubtractShift

Restore

1 00001 0000

1 1

Initially

Subtract

Shift

10111

100001100000000

SubtractShift

Restore

101110100010000

1 1

QuotientRemainder

Shift

10111

1 0000

Subtract

Second cycle

First cycle

Third cycle

Fourth cycle

00

0

0

00

1

0

1

10000

1 11 0000

11111Restore

q0Set

q0Set

q0Set

q0Set

A Q

M

1. A�0, Q�dividend, M� divisor

2. Shift left AQ by one position

3. A�A-M

4. If sign of A is 1

q0 �0

A�A+M

Else

q0�1

5. Repeat step 2 to 4 for n-1 times

Page 24: 02 09 11 - WordPress.com · Booth Algorithm • In general, in the Booth scheme, -1times the shifted multiplicand is selected when moving from 0 to 1 , ... Division = 8 0 0 0 0. 0

9/6/2011

24

Nonrestoring Division

• Avoid the need for restoring A after an unsuccessful subtraction.

• Any idea?

• Step 1: (Repeat n times)

� If the sign of A is 0, shift A and Q left one bit position and subtract M from A; otherwise, shift A and Q left and add M to A.

� Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.

• Step2: If the sign of A is 1, add M to A

Examples

A nonrestoring-division example.

Add

Restore

remainder

Remainder

0 0 0 01

1 1 1 1 10 0 0 1 1

1

Quotient

0 0 1 01 1 1 1 1

0 0 0 01 1 1 1 1

Shift 0 0 0

11000

01111

Add

0 0 0 1 1

0 0 0 0 1 0 0 0

1 1 1 0 1

Shift

Subtract

Initially 0 0 0 0 0 1 0 0 0

1 1 1 0 0000

1 1 1 0 0

0 0 0 1 1

0 0 0Shift

Add

0 0 10 0 0 01

1 1 1 0 1

Shift

Subtract

0 0 0 110000

Fourth cycle

Third cycle

Second cycle

First cycle

q0Set

q0

Set

q0

Set

q0

Set