CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs...

31
CS 362: Computer Design Lecture 13: Addition Mitchell Theys University of Illinois at Chicago October 9th, 2018

Transcript of CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs...

Page 1: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

CS 362: Computer DesignLecture 13: Addition

Mitchell TheysUniversity of Illinois at Chicago

October 9th, 2018

Page 2: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Announcements

Page 3: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Mealy vs Moore FSMS

• Moore FSMs– Output is associated with the state– Output changes on the rising edge of the clock

• Mealy FSMs– Output is associated with transitions– Output changes whenever input changes

Page 4: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Moore vs Mealy

x

y = 1

y

y = 0

bb’

b

b’

x y

b, y = 1b’, y = 0

b, y =1

b’, y = 0

clock

input

state

output

Page 5: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

You have a mealy fsm that sends output to a clocked register.  Is every output guaranteed to be saved to your 

register?A. Yes

B. No

Page 6: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

1‐bit Binary Adding

0 + 0 = 

1 + 0 = 

1 + 1 = 

Page 7: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

1‐bit Binary Adding

0 + 0 = 0

1 + 0 = 1

1 + 1 = 10

Need to account for two output bits!

Page 8: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Half Adder• Inputs a, b

• Outputs sum and carry out.

• Sum is the result of adding a and b.

• Carry out is the overflow bit.

Page 9: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Below is the truth table for the SUM output of a half adder.  What is the boolean algebra function that will give us this truth table?

A. a OR b

B. a XOR b

C. a AND b

D. a NOR b

a b Sum 

0 0 0

0 1 1

1 0 1

1 1 0

Page 10: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Below is the truth table for the CARRY output of a half adder.  What is the boolean algebra function that will give us this truth table?

A. a OR b

B. a XOR b

C. a AND b

D. a NOR b

a b Carry out

0 0 0

0 1 0

1 0 0

1 1 1

Page 11: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Half‐Adder

• co = ab

• s = a’b + ab’

Page 12: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Binary Addition with Arbitrary Number of Bits

• Just like regular, 3rd grade style addition – Make sure we carry the overflow to the next digit

• Now we need to be able to account for the carry‐in from the next least‐significant bit

Page 13: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Full Adder

ci a b co s

0 0 0

0 0 1

0 1 0

0 1 1

1 0 0

1 0 1

1 1 0

1 1 1

• co =

• s =

Page 14: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Full Adder• co = ab + cia + cib

• s =  cia’b’ + ci’a’b+ ci’ab’ +  ciab

Page 15: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Full Adder from Half Adders

• Need carry‐in, as well as carry‐out

Page 16: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

What if both half adders have carry‐out?

A. We will get the wrong answer.

B. We will ignore it, the answer will still be correct.

C. That will never happen

Page 17: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Ripple‐Carry Adder

• Create adder for an arbitrary number of bits simply by connecting carry‐out from adder n‐1 to the carry‐in for adder n

• Carry bit “ripples” up

Page 18: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Can we add a3 + b3 and a0 + b0 at the same time?

A. Yes

B. No

Page 19: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Recall: ‐7 as a 4 bit two’s compliment number is

A. 0111

B. 1000

C. 1001

D. 1111

E. None of the above

Page 20: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Subtraction: a‐b

• Just add negative version of b!

• To negate operand, transform to two’s compliment– Invert each bit– Add one to least significant bit

Page 21: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

We can use a NOT gate to invert the input.  To add one to the input, we should

A. Set the carry‐in for the least significant bit to 1.

B. Add a new “subtract” input that we set to 1 for subtraction.

C. Do something else.

Page 22: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Subtractor

• Invert bits of b

• Set cin to 1

Page 23: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Subtractor: 7 ‐ 5

Page 24: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Adder/Subtractor

• Use muxes to choose between regular/invert b• Sub input controls cin, muxes

Page 25: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Recall: Which of these will cause overflow in 4 bits?

A. 0011 + 0110

B. 1101 + 0110

C. 1100 + 1100

D. More than one of the above

E. None of the above 

Page 26: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

If there is overflowA. cout = 1

B. cout != s3

C. cout != s3, a3 = b3

A. None of the above

Page 27: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Overflow in ripple‐carry: 3 + 6

Page 28: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Overflow in ripple‐carry: ‐3 + ‐6

Page 29: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Overflow in ripple‐carry: ‐3 + 6

Page 30: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Overflow in ripple‐carry: ‐2 + ‐4

Page 31: CS 362: Computer Design Lecture 13: Addition · 2019-12-05 · Mealy vsMoore FSMS •Moore FSMs –Output is associated with the state –Output changes on the rising edge of the

Reminders

• Next Time: Comparators, N‐bit Muxes, Load Registers 5‐4‐5.6