ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned...

13
ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division

Transcript of ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned...

Page 1: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

ECE 3110: Introduction to Digital Systems

Signed Addition/Subtraction

unsigned Multiplication/Division

Page 2: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

2

Previous class Summary

Signed Conversions

Page 3: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

3

signed addition/subtraction

Two’s-complement Addition rules Subtraction rules

Overflow An operation produces a result that exceeds the

range of the number system.

Page 4: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

4

Two’s Complement Overflow

Consider two 8-bit 2’s complement numbers. I can represent the signed integers -128 to +127 using this representation.

What if I do (+1) + (+127) = +128. The number +128 is OUT of the RANGE that I can represent with 8 bits. What happens when I do the binary addition?

+127 = 7F16

+ +1 = 0116

------------------- 128 /= 8016 (this is actually -128 as a twos

complement number!!! - the wrong answer!!!)

Page 5: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

5

Detecting Two’s Complement Overflow

Two’s complement overflow occurs is:

Add two POSITIVE numbers and get a NEGATIVE result Add two NEGATIVE numbers and get a POSITIVE result

We CANNOT get two’s complement overflow if I add a NEGATIVE and a POSITIVE number together.

The Carry out of the Most Significant Bit means nothing if the numbers are two’s complement numbers.

Page 6: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

6

Some Examples

All hex numbers represent signed decimal in two’s complement format.

FF16 = -1

+ 0116 = + 1

-------- 0016 = 0

Note there is a carry out, but the answer is correct. Can’t have 2’s complement overflow when adding positive and negative number.

FF16 = -1

+ 8016 = -128

-------- 7F16 = +127 (incorrect!!)

Added two negative numbers, got a positive number. Twos Complement overflow.

Page 7: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

7

Adding Precision (unsigned)

What if we want to take an unsigned number and add more bits to it?

Just add zeros to the left.

128 = 8016 (8 bits)

= 008016 (16 bits)

= 0000008016 (32 bits)

Page 8: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

8

Adding Precision (two’s complement)

What if we want to take a twos complement number and add more bits to it? Take whatever the SIGN BIT is, and extend it to the left.

-128 = 8016 = 100000002 (8 bits)

= FF8016 = 11111111100000002 (16 bits)

= FFFFFF8016 (32 bits)

+ 127 = 7F16 = 011111112 (8 bits)

= 007F16 = 00000000011111112 ( 16 bits)

= 0000007F16 (32 bits)

This is called SIGN EXTENSION. Extending the MSB to the left works for two’s complement numbers and unsigned numbers.

Page 9: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

9

Signed 2’s-complement and unsigned binary numbers

Basic binary addition and subtraction algorithms are same

Interpretation may be different.

1101+1110

Page 10: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

10

Unsigned multiplication/division

Multiplication: shift-and-add: partial product

Division: shift-and-subtract Overflow:

divisor is 0 or Quotient would take more than m bits

Page 11: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

11

Unsigned binary multiplication: example

1011 x 1101=?Add each shifted multiplicand as it is

created to a partial product.

Page 12: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

12

What do you need to know?

Addition, subtraction of binary, hex numbers

Detecting unsigned overflowNumber ranges for unsigned, SM, 1s

complement, 2s complementOverflow in 2s complementSign extension in 2s complement

Page 13: ECE 3110: Introduction to Digital Systems Signed Addition/Subtraction unsigned Multiplication/Division.

13

Next… [Chapter 2.10--2.16]

BCD, GRAY, and other codes