Addition and Subtraction Philipp Koehn 4 September 2019 Philipp - - PowerPoint PPT Presentation

addition and subtraction
SMART_READER_LITE
LIVE PREVIEW

Addition and Subtraction Philipp Koehn 4 September 2019 Philipp - - PowerPoint PPT Presentation

Addition and Subtraction Philipp Koehn 4 September 2019 Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019 1 addition Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September


slide-1
SLIDE 1

Addition and Subtraction

Philipp Koehn 4 September 2019

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-2
SLIDE 2

1

addition

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-3
SLIDE 3

2

1-Bit Adder

  • Let’s start simple:

Adding two 1-Bit numbers

  • Truth table

A B A+B 1 1 1 1 1 1 10

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-4
SLIDE 4

3

Really 2 Operations

  • Truth table for "position 0" bit

A B A+B 1 1 1 1 1 1

xor

  • Truth table for carry bit

A B A+B carry 1 1 1 1 1

and

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-5
SLIDE 5

4

Reminder: Basic Gates

AND OR NOT NAND NOR

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-6
SLIDE 6

5

Circuits

  • "Position 0" bit

A B OUT0 1 1 1 1 1 1

xor

NAND AND OR

A B OUT0

  • Carry bit

A B OUTC 1 1 1 1 1

and

A B

AND

OUTC

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-7
SLIDE 7

6

Putting them Together

AND

CARRY

NAND AND OR

A B OUT0

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-8
SLIDE 8

7

N-Bit Addition

011 +11

  • 110
  • 110

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-9
SLIDE 9

8

N-Bit Addition

011 +11

  • 110
  • 110

1+1 = 0, carry the 1

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-10
SLIDE 10

9

N-Bit Addition

011 +11

  • 110
  • 110

1+1+1 = 1, carry the 1

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-11
SLIDE 11

10

N-Bit Addition

011 +11

  • 110
  • 110

copy carry bit

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-12
SLIDE 12

11

1-Bit Adder

AND

CARRY

NAND AND OR

A B OUT0

Our adder cannot handle carry as input yet

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-13
SLIDE 13

12

Half 1-Bit Adder

AND

CARRY

NAND AND OR

A B OUT0

1-BIT HALF ADDER

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-14
SLIDE 14

13

Building a 1-Bit Full Adder

CARRY A B

1-BIT HALF ADDER A B S C

SUM

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-15
SLIDE 15

14

Building a 1-Bit Full Adder

CARRY A B

1-BIT HALF ADDER A B S C

CARRY CARRY SUM

1-BIT HALF ADDER A B S C

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-16
SLIDE 16

15

Building a 1-Bit Full Adder

A B

1-BIT HALF ADDER A B S C

CARRY SUM

1-BIT HALF ADDER A B S C OR

CARRY

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-17
SLIDE 17

16

1-Bit Full Adder

A B

1-BIT HALF ADDER A B S C

CARRY SUM

1-BIT HALF ADDER A B S C OR

CARRY

1-BIT FULL ADDER

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-18
SLIDE 18

17

N-Bit Full Adder

011 +11

  • 110
  • 110

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-19
SLIDE 19

18

N-Bit Full Adder

011 +11

  • 110
  • 110

1-BIT FULL ADDER A B S CO CI

A0 B0 SUM0

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-20
SLIDE 20

19

N-Bit Full Adder

011 +11

  • 110
  • 110

1-BIT FULL ADDER A B S CO CI

A0 B0

1-BIT FULL ADDER A B S CO CI

A1 B1 SUM0 SUM1

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-21
SLIDE 21

20

N-Bit Full Adder

and so

  • n

...

1-BIT FULL ADDER A B S CO CI

A0 B0

1-BIT FULL ADDER A B S CO CI

A1 B1 SUM0 SUM1

1-BIT FULL ADDER A B S CO CI

A2 B2 SUM2

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-22
SLIDE 22

21

subtraction

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-23
SLIDE 23

22

First, a Trick

  • Normally, we subtract like this:

0253

  • 176
  • 0110
  • 0077

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-24
SLIDE 24

23

Computing the Inverse

  • Now we use the inverse of the subtrahend

0999

  • 176
  • 0823

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-25
SLIDE 25

24

Subtraction by Addition

  • This allows us to carry our subtraction by addition

00253 +0823

  • 01076
  • Well, with minor corrections

01076 +0001

  • 1000
  • 0077

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-26
SLIDE 26

25

Also Works in Binary

Original problem 00253

  • 0176
  • 00077

0011111101

  • 010110000
  • 0001001101

Inverse of subtrahend 00823 0001001111 Addition 00253 +0823

  • 01076

0011111101 +001001111

  • 0101001100

Corrections +0001

  • 1000
  • 0077

+000000001

  • 100000000
  • 0001001101

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-27
SLIDE 27

26

Start with N-Bit Adder

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-28
SLIDE 28

27

Invert Bits of Subtrahend

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-29
SLIDE 29

28

Add One

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3 V A0 A1 A2 A3

Trick: add one as carry in

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-30
SLIDE 30

29

Invert Overflow --- DONE

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3 V A0 A1 A2 A3 OVERFLOW SUM

mm...

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-31
SLIDE 31

30

unifying addition and subtraction machines

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-32
SLIDE 32

31

Goal

  • Not two machines for addition and subtraction

⇒ Combined adder and subtractor

  • Input:

A, B, and subtraction flag SUB

  • Output

– if SUB=0: A+B – if SUB=1: A-B

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-33
SLIDE 33

32

NOT only if SUB

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3 V A0 A1 A2 A3 OVERFLOW SUM

mm...

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-34
SLIDE 34

33

NOT only if SUB

  • Truth table

SUB X OUT 1 1 1 1 1 1

  • Looks like XOR

XOR

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019

slide-35
SLIDE 35

34

Combined Machine

4-BIT FULL ADDER A0 B3 S0 CO CI A1 A2 A3 B0 B1 B2 S1 S2 S3

B0 B1 B2 B3 SUB A0 A1 A2 A3 OVERFLOW SUM SUB SUB

Philipp Koehn Computer Systems Fundamentals: Addition and Subtraction 4 September 2019