24
Computer Arithmetic Prepared by: Buddha Shrestha Devendra Bhandari Diasy Dongol

Computer arithmetic

Embed Size (px)

Citation preview

Page 1: Computer arithmetic

Computer Arithmetic

Prepared by: Buddha Shrestha Devendra Bhandari Diasy Dongol

Page 2: Computer arithmetic

• Arithmetic means the operation with operand.

– Like

•ADDITION ( + )• SUBTRACTION ( - )•MULTIPLICATION ( * )•DIVIDE ( / )

Page 3: Computer arithmetic

Eight Conditions for Signed-Magnitude Addition/Subtraction

OperationADD

Magnitudes

SUBTRACT Magnitudes

A > B A < B A = B

(+A) + (+B) + (A + B)

(+A) + (-B) + (A – B ) - (B – A ) + (A – B )

(-A) + (+B) - (A – B ) + (B – A ) + (A – B )

(-A) + (-B) - ( A + B)

(+A) - (+B) + (A – B ) - (B – A ) + (A – B )

(+A) - (-B) + (A + B)

(-A) - (+B) - ( A + B)

(-A) - (-B) - (A – B ) + (B – A ) + (A – B )

12345678

Page 4: Computer arithmetic

Hardware for signed-magnitude addition and subtraction

A register

AVF

E

Bs

AS

B register

Complementer

Parallel AdderS

Load Sum

MMode Control

Input CarryOutput Carry

Page 5: Computer arithmetic
Page 6: Computer arithmetic

Add operation

≠ 0 =0

A>=B

As = BS

=0=1

Augend in A Added in B

END

As BS+

EA A + B

AVF E

EA A + B +1AVF 0

EA

As 0

A A

A A+1As As

As ≠ BS

=0 =1A<B

Page 7: Computer arithmetic

• For Example of Addition

• (+1) + (+2)

(+A) + (+B)

Page 8: Computer arithmetic

Add operation

≠ 0 =0

A>=B

As = BS

=0=1

Augend in A Added in B

END

As BS+

EA A + B

AVF E

EA A + B +1AVF 0

EA

As 0

A A

A A+1As As

As ≠ BS

=0 =1A<B

(+1) + (+2)

Page 9: Computer arithmetic

• (-1) + (+2)

(-A) + (+B)

Page 10: Computer arithmetic

Add operation

≠ 0 =0

A>=B

As = BS

=0=1

Augend in A Added in B

END

As BS+

EA A + B

AVF E

EA A + B +1AVF 0

EA

As 0

A A

A A+1As As

As ≠ BS

=0 =1A<B

(-1) + (+2)

Page 11: Computer arithmetic

• For Example of Subtraction

• (+1) - (-2)(+A) - (-B)

Page 12: Computer arithmetic

As ≠ BS

Subtract operation

≠ 0 =0

A>=B

As = BS

=0 =1

Miuend in A Subtrahend in B

END

As BS+

EA A + B

AVF E

EA A + B +1AVF 0

EA

As 0

A A

A A+1As As

=0 =1A<B

(+1) - (-2)

Page 13: Computer arithmetic

• (+5) – (+2)

(+A) – (+B)

Page 14: Computer arithmetic

As ≠ BS

Subtract operation

≠ 0 =0

A>=B

As = BS

=0 =1

Miuend in A Subtrahend in B

END

As BS+

EA A + B

AVF E

EA A + B +1AVF 0

EA

As 0

A A

A A+1As As

=0 =1A<B

(+5) – (+2)

Page 15: Computer arithmetic

Figure: Hardware for signed-2’s complement addition and subtraction.

BR register

Complementer and parallel adder

AC register

V

Overflow

Page 16: Computer arithmetic

Subtract

Figure: Algorithm for adding and subtracting numbers in signed-2’s complement representation.

Add

Augend in ACAddend in BR

AC AC + BR V overflow

END

Minuend in ACSubtrahend in BR

AC AC + BR + 1V overflow

END

Page 17: Computer arithmetic

Figure: Hardware for multiply operation

Bs

B register Sequence counter (SC)

Complementer and parallel adder

A register Q register

As

E

Qs

(rightmost bit)Qn

0

Page 18: Computer arithmetic

SC

Qn

Multiply operation

Multiplicand in BMultiplier in Q

As Qs Bs

Qs Qs Bs

A 0,E 0SC n-1

EA A + Bshr EAQSC SC-1

END(products is in AQ)

= 0

= 0 = 1

≠ 0

Figure: Flowchart for multiply operation.

Page 19: Computer arithmetic

BOOTH MULTIPLICATION ALGORITHM

Introduction Hardware for Booth Algorithm Booth Algorithm for multiplication of signed 2’s

complement numbers

Page 20: Computer arithmetic

INTRODUCTION

multiplication algorithm that multiplies two signed binary numbers in two's complement notation.

 was invented by Andrew Donald Booth in 1950  used desk calculators that were faster at shifting

 than adding and created the algorithm to increase their speed

is of interest in the study of computer architecture.

Page 21: Computer arithmetic

Hardware for Booth Algorithm

Sign bits are not separated from the rest of the registers

rename registers A,B, and Q as AC,BR and QR respectively

Qn designates the least significant bit of the multiplier in register QR

Flip-flop Qn+1 is appended to QR to facilitate a double bit inspection of the multiplier

BR register Sequence COUNTER (SC)

Complementer and parallel adder

AC register QR register

Qn Qn+1

Page 22: Computer arithmetic

Booth Algorithm for multiplication of signed 2’s

complement numbers

Page 23: Computer arithmetic

= 10

=00=11

Multiplicand in BRMultiplier in QR

AC<-0Qn+1<-0

SC<-n

Qn Qn+1

AC<-AC+BR+1 AC<-AC+BR

ASHR(AC & QR)SC<-SC-1

SC END

Multiply

≠ 0 = 0

= 01

Page 24: Computer arithmetic

Thank You