Docsity

Arithmetic Circuits: Creating Logic Gates for Addition and Subtraction, Slides of Computer Science

Toggle sidebar
bg1
Arithmetic Circuits
ArithmeticArithmetic
Computer Architecture
dO i ti
and Organization
Goal for Today
• Create logic gates that perform arithmetic
Elementary School
17 010001
+ 7 +000111
24 011000
You add two numbers together. If the sum
is greater than the number base, you add
one to the next column. When you add
two numbers, you may also have to add
the carry from the column to the right.
1 Bit Adder
• A one bit adder has three inputs, numbers
A and B and Carry in. There are two
ttthS dC t
ou
t
pu
t
s,
th
e
S
um an
d
C
arry ou
t
.
AB
one bit adder Cin
Cout
Sum
Docsity.com
pf3
pf4
pf5
pf8
pf9
pfa
pfd

Partial preview of the text

Download Arithmetic Circuits: Creating Logic Gates for Addition and Subtraction and more Slides Computer Science in PDF only on Docsity!

ArithmeticArithmetic

Computer Architecture

d O

i^

ti

and Organization

Goal for Today

  • Create logic gates that perform arithmetic

Elementary School

You add two numbers together. If the sumis greater than the number base, you addone to the next column. When you addtwo numbers, you may also have to addthe carry from the column to the right.

1 Bit Adder

  • A one bit adder has three inputs, numbers

A and B and Carry in. There are two

t^

t^

th

S

d C

t

outputs, the Sum and Carry out.

A

B

one bit adder

Cin

Cout

Sum

Multiple Bit Adder

A one bit adder

B

A one bit adder

B

A one bit adder

B

Cout

Sum

Sum

Sum

1 bit Adder Truth Table

figure from textbook

Addition Sum

A’ B’
A’ B
A B
A B’

Cin’

Cin

Sum = A’BC’ + AB’C’ + A’B’C + ABC

Addition Carry Out

A’ B’
A’ B
A B
A B’

Cin’

Cin

Cout = AB + BC + AC

Saving Status

Status

flag

Detection

flag Overflow

XOR of carry into and out of the sign bit

Sign

Copy of the sign bit

Zero

NOR of all result bits

Carry

Carry into the sign bit

Intel Status Register

  • The status register records the results of

ti

th

i^

t^

ti

executing the instruction.

  • Performing arithmetic sets the status

register.

  • The compare instruction does a

subtraction but doesn’t store the resultssubtraction, but doesn t store the results.It just sets the status flags.

  • All jump instructions are based on the

status register

1 Bit Subtracter

  • A one bit subtracter has three inputs,

numbers X and Y and Borrow in. There

t^

t^

t^

th

Diff

d B

are two outputs, the Difference and Borrowout.

X

Y

one bit subtract

Borrow

in

Borrow

out

Difference

X-Y Subtracter Truth Table

X

Y

B

in

B

out

Diff

0

0

0

0

0

Diff = X’YB

in

’ + XY’ B

in

0

0

0

0

0

0

0

1

1

1

0

1

0

1

1

0

1

1

1

0

1

0

0

0

1

1

0

1

0

0

X’ Y’

X’ Y

X Y

X Y’

Bin’

+ X’Y’ B

in

+ XYB

in

1

0

1

0

0

1

1

0

0

0

1

1

1

1

1

Bin

Docsity.com

What is the equation for B

out

25%

25%

25%

25%

1. B

out

= XY + B

in

out

in

2. B

out

= YB

in

+ XB

in

3. B

out

= XB

in

’+YB

in

’+XY
4. B

out

= XY + X’B

in

Bout = XY + Bi...

Bout = YBin + ...

Bout = XBin’+Y...

Bout = XY + X’...

The equation for B

out

X

Y

B

in

B

out

Diff

0

0

0

0

0

B

out

= XB

in

’ + YB

in

’ + XY

0

0

0

0

0

0

0

1

1

1

0

1

0

1

1

0

1

1

1

0

1

0

0

0

1

1

0

1

0

0

X’ Y’

X’ Y

X Y

X Y’

Bin’

out

in

in

1

0

1

0

0

1

1

0

0

0

1

1

1

1

1

Bin

Subtraction

  • Instead of building a separate subtraction

circuit, you can add the negative of theoperand.

  • To make a twos complement number

negative, you must invert the bits and add one

  • A NOT gate can be used to invert all the bits.• Setting the Carry In on the rightmost bit will

add one to the result.

A+B’+1 = A + (B’+1) = A + (-B) = A - B

Draw a Subtraction Circuit

  • Using one bit adder boxes and OR, AND

or NOT gates, draw the logic diagram for aor NOT gates, draw the logic diagram for afour bit twos complement A - B subtractioncircuit.

A

B

one bit adder

Carry

out

Carry

in

Carry Equations

  • We can express the carry as:C

i+

= G
  • (Pi

i^

* C

)i

C

i+

= G

i+

+ (P

i+

* G

) + (Pi^

i+

* P

i^

* C

)i

C

i+

= G

i+

+(P

i+

* G

i+

) + (P

i+

* P

i+

* G

i+

(P

i+

* P

i+

* P

i+

* G

) +i

(P

i+

* P

i+

* P

i+

* P
  • Ci

)i

4 bit Adder with Look Ahead Carry

diagram from Digital Fundamentals by Thomas Floyd

Reduced Propagation

  • The simple n bit ripple adder took O(2n)

ti

t^

dd

bit

d

t^

ti

time to add n bits due to carry propagation.

  • With carry look ahead, it takes O(3) time to

propagate the carry. The look aheadrequires more circuitry.

Further Simplification

  • Creating a big adder out of groups of

adders can reduce propagation and circuitry

As four bit adder

Bs

As four bit adder

Bs

As four bit adder

Bs

Cout

Sums

Sums

Sums

Multiplication Tables

Decimal

Binary

1

2

3

4

5

6

7

8

9

10

1

1

2

3

4

5

6

7

8

9

10

2

2

4

6

8

10

12

14

16

18

20

3

3

6

9

12

15

18

21

24

27

30

4

4

8

12

16

20

24

28

32

36

40

5

5

10

15

20

25

30

35

40

45

50

6

6

12

18

24

30

36

42

48

54

60

7

7

14

21

28

35

42

49

56

63

70

0

1

0

0

0

1

0

1

7

7

14

21

28

35

42

49

56

63

70

8

8

16

24

32

40

48

56

64

72

80

9

9

18

27

36

45

54

63

72

81

90

10

10

20

30

40

50

60

70

80

90

100

Multiplication

decimal

binary

Binary Multiplication

110 *101^101110

copy number when bit is one

1 add zero when bit is zero

01 copy number when bit is zero

add the results in proper column

add the results in proper column

Add and Shift

  • Multiplication can be done by a series of

adds and left shifts.adds and left shifts.

  • Assume you have operands A & B and

Product P (initially zero).

for

each

bit

i

in

B

if (B

i

is

one)

i

add

A

to

P

shift A

left

by

one

bit

B

1

is zero so do nothing

A
P
B

Shift A left one bit^10100

A
P
B

B

2

is 1 so Add

A
P
B

+

Shift A left one bit^01000

A
P
B

B

3

is zero so do nothing

A
P
B

Shift A left one bit^10000

A
P
B

B

4

is zero so do nothing

A
P
B

Done

A
P
B

3 x 3 Example

3 x 3 Example

3 x 3 Example

Division

  • Division is difficult.

(Every elementary school

hild k

h

child knows that.)

  • Some small computers do not have

multiplication or division.

  • Some have multiplication but not division.