ECE 171 Digital Circuits: Prof. Mark G. Faust Maseeh College of Engineering and Computer Science

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 22

ECE171 DigitalCircuits

Prof.MarkG.Faust MaseehCollegeofEngineering andComputerScience

Lecture2
Topics
BinaryArithmetic(Unsignedbinaryoperands) Signed i dnumber b representations i
SignedMagnitude DiminishedRadixComplement(OnesComplement) RadixComplement(TwosComplement)

BinaryArithmeticRevisitedandOverflow SignExtension

BinaryArithmetic
Rulesforcarrysameasindecimal
1 carry

0 + 0 0

0 + 1 1

1 + 0 1

1 + 1 10

UnsignedBinary(UB)Addition
Examples(4bitword) 2+6
11

11+6
1 11

0010 0110 1000

2 +6 8

1011 + 0110 10001


Overflow

11 +6 17
17>241
4

Overflow(Underflow)
Definition: Resultofanarithmeticoperation p istoolarge g (or ( small) )tobe representedinnumberofbitsavailable Detection: Varieswiththerepresentation.Forunsignedbinary,its determinedbyacarryoutoftheMSB

1 11

11 8bitoperands

10101101 + 01101100 100011001

SignedNumbers
Havebeenassumingnonnegativenumbers
Unsigned g Binary y(UB) ( )

Severalrepresentationsforsignednumbers
SignMagnitude(SM) DiminishedRadixComplement(DRC)
1sComplement

RadixComplement(RC)
2sComplement
6

SignMagnitude
MSBfunctionsassignbit 0=positive 1=negative Rangeofnumbers: (2n1 1)to+(2 (2n1 1)

n=6
Tworepresentationsfor0 Negativeformedby complementingsignbit 1510=001111SM 1510=101111SM 010100SM =2010 110100SM =2010
7

DiminishedRadixComplement(DRC)
CalledOnesComplement MSBindicatessign 0=positive 1=negative (b notasignbit!) (but b !) Rangeofnumbers: (2n1 1)to+(2n1 1) Tworepresentationsfor0 Negative egat eformed o edbyco complementing p e e t g e entire t eword od (calledtakingtheonescomplement) 1510=001111DRC 1510=110000DRC 010100DRC =2010 101011DRC =2010
8

RadixComplement(RC)
CalledTwosComplement g MSBindicatessign 0=positive 1=negative (butnotasignbit) Rangeofnumbers: (2n1)to+(2n1 1) Onlyonerepresentationfor0 Negativeformedbycomplementingentireword andadding1(calledtakingthetwoscomplement) 1510=001111RC 1510=110001RC 010100RC =2010 101100RC =2010
9

TwosComplement SpecialCases
Example:TakeTwosComplement(RC) of0000(010)
0000
1 1 1

1111 +1 0000

Complement AddOne

IgnorecarryoutofMSB

10

TwosComplement SpecialCases
Example:TakeTwosComplement(RC) of1000(810)(mostnegative)
1000
1 1 1

0111 +1 1000

Complement AddOne

Cantrepresent abs(mostnegativenumber)

11

ConversionsofSigned Representations
Fromdecimal
Representthe h absolute b l value l of fthe h number b inUB Usethecorrectnumberofbits(addleading0s) Ifthedecimalnumberisnegative,usetheappropriateruletonegate therepresentation
S/M complementthesignbit DRC(onescomplement) complementeverybit RC(twoscomplement) complementeverybit,add1

To T decimal d i l
Ifnumberis+,convertfromUBtodecimal(done!) Ifnumberis useappropriateruletonegateit(obtainitsabsolute value)
S/M complementthesignbit DRC(onescomplement) complementeverybit RC(twoscomplement) complementeverybit,add1

Convert C this hi (positive) ( i i )number b asthough h hUBtodecimal d i l Addanegativesign

12

WhydoweuseRC (TwosComplement)?
Onlyonerepresentationforzero SimplifiedAddition
SignMagnitudeAddition
Mustconsidertwooperandswithoutsignbits Ifsignbitssame:performadd,checkoverflow Ifsignbitsdifferent:subtract(twocases)
+Aand B A B Aand+B B A

Generatecorrectsignbitforsum

RadixComplement(TwosComplement)Addition
Justadd!

SimpleSubtraction
Doneviaaddition
A + B A B=A+(B) Caution:Canttakenegativeofmostnegativenumber

13

BinaryArithmetic
UnsignedBinary(UB) SignedBinary(SB) DiminishedRadixComplement(DRC)
1scomplement

Rarely used

RadixComplement(RC)
2scomplement

14

RadixComplement(RC)orTwos ComplementAddition
Examples(4bitword) 7+(2)
1 11

5+(7)
1

0111 7 + 1110 +(2) 10101 5


IgnorecarryoutofMSB

0101 + 1001 1110

5 +(7) (2)
15

RadixComplement(RC)orTwos ComplementAddition
Examples(4bitword) 7+(2)
1

1001 7 + 1110 +(2) 10111 9


IgnorecarryoutofMSB

Weaddedtwo negativenumbers andgotapositive result! l!


Overflow!! 9< (23)
16

CarryandOverflow
Isthisanoverflowcondition?
1 1 1011 00

10101101 + 01101100 100011001


Ifthisisanunsignedbinary(UB)number Yes!
17

CarryandOverflow
Isthisanoverflowcondition?
1 1 1011 00

10101101 + 01101100 100011001


Ifthisisaradixcomplement(RC)number No!
Anegativenumberplusapositivenumbercannotproduceanoverflow
18

CarryandOverflow RadixComplement(2sComplement)
Consider:
Positive+Negative Neveroverflow Negative+Negative Overflowpossible Positive+Positive Overflowpossible

DetectingOverflow:
Ifsigns g ofaddendsaresameandsign g ofsumis different EquivalenttoCSBP CSBP+1
19

CarryandOverflow
CSBP+1 CSBP 1 1 1011 00 C Carry SBP SignBitPosition

10101101 + 01101100 100011001

20

RadixComplement(RC)Addition
Examples(4bitword) 7+(2)
CSBP+1 CSBP 1 000

CSBP+1 CSBP

1001 7 + 1110 +(2) 10111 9

Weaddedtwo negativenumbers andgotapositive result! l!


Overflow!

9< (23)

21

SignExtension
Whathappenswhenyoumoveanumberfromasmallerword sizetoalargerone? UB
00000011 (3) 0000000000000011 (3)

S/M
00000011 (3) 0000000000000011 (3)

RC(2scomplement)
00000011 (3) 0000000000000011 (3)

11111101 (253) 0000000011111101 (253)

11111101 (125) 1000000001111101 (125)

11111101 (3) 0000000011111101 (+253!)

11111101 (3)

t dth extend thesign i bitleft l ftthrough th hthe th newMSB

1111111111111101 (3)
22

You might also like