Top Banner
Computer Arithmetic Algorithms Prof. Dae Hyun Kim School of Electrical Engineering and Computer Science Washington State University Number Representations
21

Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

Mar 24, 2021

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

Computer Arithmetic Algorithms

Prof. Dae Hyun Kim School of Electrical Engineering and Computer Science

Washington State University

Number Representations

Page 2: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

2

Information

β€’ Textbook – Israel Koren, β€œComputer Arithmetic Algorithms,” Prentice Hall, 1993.

Page 3: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

3

Outline

β€’ Binary number system

β€’ Radix conversion

β€’ Negative numbers – Signed-magnitude – One’s complement – Two’s complement

β€’ Addition and subtraction

β€’ Arithmetic shift operations (sign extension)

Page 4: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

4

The Binary Number System

β€’ A binary number of length 𝑛𝑛 (π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0)

– π‘₯π‘₯𝑖𝑖: bit (∈ {0,1})

β€’ An 𝑛𝑛-digit binary number

𝑋𝑋 = π‘₯π‘₯π‘›π‘›βˆ’12π‘›π‘›βˆ’1 + π‘₯π‘₯π‘›π‘›βˆ’22π‘›π‘›βˆ’2 + β‹―+ π‘₯π‘₯121 + π‘₯π‘₯020 = οΏ½π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’1

𝑖𝑖=0

– π‘₯π‘₯𝑖𝑖 ∈ {0,1}

β€’ Example – 10112 = 1 βˆ™ 23 + 0 βˆ™ 22 + 1 βˆ™ 21 + 1 βˆ™ 20 = 11

radix

Page 5: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

5

The Binary Number System

β€’ Radix-10 numbers: decimal numbers – (101)10= 101

β€’ Radix-2 numbers: binary numbers

– (101)2= 5

β€’ Range of representable numbers [π‘‹π‘‹π‘šπ‘šπ‘–π‘–π‘›π‘›,π‘‹π‘‹π‘šπ‘šπ‘šπ‘šπ‘šπ‘š]

– Example: The range of 4-bit unsigned binary numbers: [0, 15]

β€’ Overflow – An arithmetic operation resulting in a number larger than π‘‹π‘‹π‘šπ‘šπ‘šπ‘šπ‘šπ‘š or

smaller than π‘‹π‘‹π‘šπ‘šπ‘–π‘–π‘›π‘›

Page 6: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

6

The Binary Number System

β€’ The conventional number systems – Nonredundant

β€’ Every number has a unique representation. – Weighted

β€’ 𝑋𝑋 = βˆ‘ π‘₯π‘₯π‘–π‘–π‘€π‘€π‘–π‘–π‘›π‘›βˆ’1𝑖𝑖=0

β€’ 𝑀𝑀𝑖𝑖: weight – Positional

β€’ 𝑀𝑀𝑖𝑖 depends only on the position of the digit π‘₯π‘₯𝑖𝑖. β€’ 𝑀𝑀𝑖𝑖 = π‘Ÿπ‘Ÿπ‘–π‘– β€’ 0 ≀ π‘₯π‘₯𝑖𝑖 ≀ π‘Ÿπ‘Ÿ βˆ’ 1

– Otherwise (if π‘₯π‘₯𝑖𝑖 β‰₯ π‘Ÿπ‘Ÿ), the system becomes redundant.

X D

π‘₯π‘₯π‘˜π‘˜

π‘₯π‘₯𝑖𝑖 𝑑𝑑𝑗𝑗

redundant

Page 7: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

7

The Binary Number System

β€’ A mixed number (fixed-point representation) (π‘₯π‘₯π‘˜π‘˜βˆ’1 π‘₯π‘₯π‘˜π‘˜βˆ’2 … π‘₯π‘₯1 π‘₯π‘₯0 . π‘₯π‘₯βˆ’1π‘₯π‘₯βˆ’2 … π‘₯π‘₯βˆ’π‘šπ‘š)π‘Ÿπ‘Ÿ

= (π‘₯π‘₯π‘˜π‘˜βˆ’1π‘Ÿπ‘Ÿπ‘˜π‘˜βˆ’1 + π‘₯π‘₯π‘˜π‘˜βˆ’2π‘Ÿπ‘Ÿπ‘˜π‘˜βˆ’2 + β‹―+ π‘₯π‘₯1π‘Ÿπ‘Ÿ1 + π‘₯π‘₯0π‘Ÿπ‘Ÿ0) + (π‘₯π‘₯βˆ’1π‘Ÿπ‘Ÿβˆ’1 + β‹―+ π‘₯π‘₯βˆ’π‘šπ‘šπ‘Ÿπ‘Ÿβˆ’π‘šπ‘š)

= οΏ½ π‘₯π‘₯π‘–π‘–π‘Ÿπ‘Ÿπ‘–π‘–π‘˜π‘˜βˆ’1

𝑖𝑖=βˆ’π‘šπ‘š

β€’ π‘Ÿπ‘Ÿβˆ’π‘šπ‘š: indicates the position of the radix point.

β€’ ulp: unit in the last position

– 𝑒𝑒𝑒𝑒𝑒𝑒 = π‘Ÿπ‘Ÿβˆ’π‘šπ‘š

integral part fractional part

Page 8: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

8

Radix Conversion

β€’ Given – 𝑋𝑋 = 𝑋𝑋𝐼𝐼 + 𝑋𝑋𝐹𝐹 = βˆ‘ π‘₯π‘₯π‘–π‘–π‘Ÿπ‘Ÿπ‘–π‘–π‘˜π‘˜βˆ’1

𝑖𝑖=0 + βˆ‘ π‘₯π‘₯π‘–π‘–π‘Ÿπ‘Ÿπ‘–π‘–βˆ’1𝑖𝑖=βˆ’π‘šπ‘š

β€’ 𝑋𝑋𝐼𝐼: integral part β€’ 𝑋𝑋𝐹𝐹: fractional part

– π‘Ÿπ‘Ÿπ·π·: destination number system

β€’ Integral part 𝑋𝑋𝐼𝐼 = π‘₯π‘₯0 + π‘Ÿπ‘Ÿπ·π·(π‘₯π‘₯1 + π‘Ÿπ‘Ÿπ·π·(π‘₯π‘₯2 + β‹―+ π‘Ÿπ‘Ÿπ·π·(π‘₯π‘₯π‘˜π‘˜βˆ’2 + π‘Ÿπ‘Ÿπ·π·π‘₯π‘₯π‘˜π‘˜βˆ’1)))

0 ≀ π‘₯π‘₯𝑖𝑖 < π‘Ÿπ‘Ÿπ·π· – π‘₯π‘₯0 = 𝑋𝑋𝐼𝐼 π‘šπ‘šπ‘šπ‘šπ‘‘π‘‘ π‘Ÿπ‘Ÿπ·π· – π‘žπ‘ž0 = π‘₯π‘₯1 + π‘Ÿπ‘Ÿπ·π· π‘₯π‘₯2 + π‘Ÿπ‘Ÿπ·π· π‘₯π‘₯3 + β‹― – π‘₯π‘₯1 = π‘žπ‘ž0 π‘šπ‘šπ‘šπ‘šπ‘‘π‘‘ π‘Ÿπ‘Ÿπ·π· – ...

Page 9: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

9

Radix Conversion

β€’ Fractional part 𝑋𝑋𝐹𝐹 = π‘Ÿπ‘Ÿπ·π·βˆ’1(π‘₯π‘₯βˆ’1 + π‘Ÿπ‘Ÿπ·π·βˆ’1(π‘₯π‘₯βˆ’2 + β‹―+ π‘Ÿπ‘Ÿπ·π·βˆ’1(π‘₯π‘₯βˆ’ π‘šπ‘šβˆ’1 + π‘Ÿπ‘Ÿπ·π·βˆ’1π‘₯π‘₯βˆ’π‘šπ‘š)))

0 ≀ π‘₯π‘₯𝑖𝑖 < π‘Ÿπ‘Ÿπ·π·

– π‘₯π‘₯βˆ’1: the integral part of π‘‹π‘‹πΉπΉπ‘Ÿπ‘Ÿπ·π· – π‘šπ‘šβˆ’1 = π‘Ÿπ‘Ÿπ·π·βˆ’1(π‘₯π‘₯βˆ’2 + β‹―+ π‘Ÿπ‘Ÿπ·π·βˆ’1(π‘₯π‘₯βˆ’ π‘šπ‘šβˆ’1 + π‘Ÿπ‘Ÿπ·π·βˆ’1π‘₯π‘₯βˆ’π‘šπ‘š)) – π‘₯π‘₯βˆ’2: the integral part of π‘šπ‘šβˆ’1π‘Ÿπ‘Ÿπ·π· – ...

β€’ Example

– 46.37510 = 101110.0112

Page 10: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

10

Negative Numbers: Signed-Magnitude

β€’ Representation (π‘₯π‘₯𝑠𝑠 π‘₯π‘₯π‘›π‘›βˆ’2π‘₯π‘₯π‘›π‘›βˆ’3 … π‘₯π‘₯1π‘₯π‘₯0)

β€’ Positive numbers: 0xxxxx – 0xxxxx2

β€’ Negative numbers: (r-1)xxxxx – 1xxxxx2

β€’ Range of positive numbers for (𝑠𝑠 π‘₯π‘₯π‘˜π‘˜βˆ’2π‘₯π‘₯π‘˜π‘˜βˆ’3 … π‘₯π‘₯1π‘₯π‘₯0 . π‘₯π‘₯βˆ’1π‘₯π‘₯βˆ’2 … π‘₯π‘₯βˆ’π‘šπ‘š)

– [0, π‘Ÿπ‘Ÿπ‘˜π‘˜βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒] β€’ Range of negative numbers for (𝑠𝑠 π‘₯π‘₯π‘˜π‘˜βˆ’2π‘₯π‘₯π‘˜π‘˜βˆ’3 … π‘₯π‘₯1π‘₯π‘₯0 . π‘₯π‘₯βˆ’1π‘₯π‘₯βˆ’2 … π‘₯π‘₯βˆ’π‘šπ‘š)

– [βˆ’(π‘Ÿπ‘Ÿπ‘˜π‘˜βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒), 0]

sign magnitude

Page 11: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

11

Negative Numbers: Signed-Magnitude

β€’ Problems – Two zeros

β€’ 0000...0 β€’ 1000...0

– Difficulties in subtraction β€’ If X>Y, X-Y is ok. β€’ However, Y-X is -(X-Y), so we should compute X-Y, then set the MSB to 1.

Page 12: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

12

Negative Numbers: Complement

β€’ Represent –Y by R – Y. β€’ Then, –(–Y) = R – (R – Y) = Y. β€’ If X>Y>0, Y – X = Y + (R – X) = R – (X – Y) = X – Y.

β€’ Two requirements

– When X>Y>0, X – Y = X + (R – Y) = R + (X – Y) should be X – Y. – Computation of R – Y should be simple.

β€’ Notation

π‘₯π‘₯𝑖𝑖� = π‘Ÿπ‘Ÿ βˆ’ 1 βˆ’ π‘₯π‘₯𝑖𝑖 𝑋𝑋� = (π‘₯π‘₯π‘˜π‘˜βˆ’1, π‘₯π‘₯π‘˜π‘˜βˆ’2, … , π‘₯π‘₯0, π‘₯π‘₯βˆ’1, … , π‘₯π‘₯βˆ’π‘šπ‘š) 𝑋𝑋 + 𝑋𝑋� = ( π‘Ÿπ‘Ÿ βˆ’ 1 , π‘Ÿπ‘Ÿ βˆ’ 1 , … , (π‘Ÿπ‘Ÿ βˆ’ 1))

𝑋𝑋 + 𝑋𝑋� + 𝑒𝑒𝑒𝑒𝑒𝑒 = π‘Ÿπ‘Ÿπ‘˜π‘˜

Page 13: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

13

Negative Numbers: Complement

β€’ One’s complement (Diminished-radix complement) – 𝑅𝑅 = π‘Ÿπ‘Ÿπ‘˜π‘˜ βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 – βˆ’π‘‹π‘‹ = 𝑅𝑅 βˆ’ 𝑋𝑋 = 𝑋𝑋� – When X>Y>0, π‘Œπ‘Œ βˆ’ 𝑋𝑋 = π‘Œπ‘Œ + 𝑅𝑅 βˆ’ 𝑋𝑋 = 𝑅𝑅 βˆ’ 𝑋𝑋 βˆ’ π‘Œπ‘Œ = βˆ’(π‘Œπ‘Œ βˆ’ 𝑋𝑋) – When X>Y>0, 𝑋𝑋 βˆ’ π‘Œπ‘Œ = 𝑋𝑋 + 𝑅𝑅 βˆ’ π‘Œπ‘Œ = 𝑅𝑅 + 𝑋𝑋 βˆ’ π‘Œπ‘Œ = π‘Ÿπ‘Ÿπ‘˜π‘˜ + 𝑋𝑋 βˆ’ π‘Œπ‘Œ βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 =

𝑋𝑋 βˆ’ π‘Œπ‘Œ βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 β€’ This requires a correction step (add ulp).

– When X>0, Y>0, βˆ’π‘‹π‘‹ βˆ’ π‘Œπ‘Œ = 𝑅𝑅 βˆ’ 𝑋𝑋 + 𝑅𝑅 βˆ’ π‘Œπ‘Œ = 𝑅𝑅 + 𝑅𝑅 βˆ’ 𝑋𝑋 + π‘Œπ‘Œ = π‘Ÿπ‘Ÿπ‘˜π‘˜ + 𝑅𝑅 βˆ’π‘‹π‘‹ + π‘Œπ‘Œ = 𝑅𝑅 βˆ’ 𝑋𝑋 + π‘Œπ‘Œ = βˆ’(𝑋𝑋 + π‘Œπ‘Œ)

β€’ Two’s complement (Radix complement)

– 𝑅𝑅 = π‘Ÿπ‘Ÿπ‘˜π‘˜ – βˆ’π‘‹π‘‹ = 𝑅𝑅 βˆ’ 𝑋𝑋 = 𝑋𝑋� + 𝑒𝑒𝑒𝑒𝑒𝑒 – When X>Y>0, π‘Œπ‘Œ βˆ’ 𝑋𝑋 = π‘Œπ‘Œ + 𝑅𝑅 βˆ’ 𝑋𝑋 = 𝑅𝑅 βˆ’ π‘Œπ‘Œ βˆ’ 𝑋𝑋 = βˆ’(π‘Œπ‘Œ βˆ’ 𝑋𝑋) – When X>Y>0, 𝑋𝑋 βˆ’ π‘Œπ‘Œ = 𝑋𝑋 + 𝑅𝑅 βˆ’ π‘Œπ‘Œ = 𝑅𝑅 + 𝑋𝑋 βˆ’ π‘Œπ‘Œ = π‘Ÿπ‘Ÿπ‘˜π‘˜ + 𝑋𝑋 βˆ’ π‘Œπ‘Œ = 𝑋𝑋 βˆ’ π‘Œπ‘Œ – When X>0, Y>0, βˆ’π‘‹π‘‹ βˆ’ π‘Œπ‘Œ = 𝑅𝑅 βˆ’ 𝑋𝑋 + 𝑅𝑅 βˆ’ π‘Œπ‘Œ = 𝑅𝑅 + 𝑅𝑅 βˆ’ 𝑋𝑋 + π‘Œπ‘Œ = π‘Ÿπ‘Ÿπ‘˜π‘˜ + 𝑅𝑅 βˆ’

𝑋𝑋 + π‘Œπ‘Œ = 𝑅𝑅 βˆ’ 𝑋𝑋 + π‘Œπ‘Œ = βˆ’(𝑋𝑋 + π‘Œπ‘Œ)

Page 14: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

14

Two’s Complement Representation

β€’ One zero – 000...0

β€’ A negative number that does not have a positive equivalent – 100...0

β€’ Range – [βˆ’2π‘›π‘›βˆ’1, 2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒]

β€’ 𝑋𝑋 = βˆ’π‘₯π‘₯π‘›π‘›βˆ’1 βˆ™ 2π‘›π‘›βˆ’1 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2

𝑖𝑖=0 Proof) If π‘₯π‘₯π‘›π‘›βˆ’1 = 0 (positive), 𝑋𝑋 = βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2

𝑖𝑖=0 = βˆ’π‘₯π‘₯π‘›π‘›βˆ’1 βˆ™ 2π‘›π‘›βˆ’1 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0 .

If π‘₯π‘₯π‘›π‘›βˆ’1 = 1 (negative), 𝑋𝑋 = βˆ’ 𝑋𝑋� + 𝑒𝑒𝑒𝑒𝑒𝑒 = βˆ’[βˆ‘ π‘₯π‘₯𝑖𝑖�2π‘–π‘–π‘›π‘›βˆ’1𝑖𝑖=0 + 1]

= βˆ’ βˆ‘ 1 βˆ’ π‘₯π‘₯𝑖𝑖 2π‘–π‘–π‘›π‘›βˆ’1𝑖𝑖=0 + 1 = βˆ’ 2𝑛𝑛 βˆ’ 1 βˆ’ βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’1

𝑖𝑖=0 + 1 = βˆ’2𝑛𝑛 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’1

𝑖𝑖=0 = βˆ’2π‘›π‘›βˆ’1 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0

Page 15: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

15

One’s Complement Representation

β€’ Two zeros – 000...0 – 111...1

β€’ Range

– [βˆ’ 2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 , 2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 ]

β€’ 𝑋𝑋 = βˆ’π‘₯π‘₯π‘›π‘›βˆ’1 2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0

Proof) If π‘₯π‘₯π‘›π‘›βˆ’1 = 0 (positive), 𝑋𝑋 = βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0 = βˆ’π‘₯π‘₯π‘›π‘›βˆ’1 βˆ™ (2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒) +

βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0 .

If π‘₯π‘₯π‘›π‘›βˆ’1 = 1 (negative), 𝑋𝑋 = βˆ’π‘‹π‘‹οΏ½ = βˆ’βˆ‘ π‘₯π‘₯𝑖𝑖�2π‘–π‘–π‘›π‘›βˆ’1𝑖𝑖=0 = βˆ’βˆ‘ 1 βˆ’ π‘₯π‘₯𝑖𝑖 2π‘–π‘–π‘›π‘›βˆ’1

𝑖𝑖=0 = βˆ’ 2𝑛𝑛 βˆ’ 1 βˆ’ βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’1

𝑖𝑖=0 = βˆ’2𝑛𝑛 + 1 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’1𝑖𝑖=0

= βˆ’2π‘›π‘›βˆ’1 + 1 + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2𝑖𝑖=0 = βˆ’π‘₯π‘₯π‘›π‘›βˆ’1 βˆ™ (2π‘›π‘›βˆ’1 βˆ’ 𝑒𝑒𝑒𝑒𝑒𝑒) + βˆ‘ π‘₯π‘₯𝑖𝑖2π‘–π‘–π‘›π‘›βˆ’2

𝑖𝑖=0

Page 16: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

16

Addition and Subtraction

β€’ Signed-magnitude

– As shown above, addition and subtraction of signed-magnitude numbers need corrections.

overflow

0 1 0 1 1 (11) + 0 0 1 1 0 (6) = 1 0 0 0 1 (-1)

0 1 0 1 1 (11) + 0 0 0 1 0 (2) = 0 1 1 0 1 (13)

1 0 0 1 1 (-3) + 1 0 1 0 1 (-5) =1 0 1 0 0 0 (+8)

overflow

1 1 0 0 0 (-8) + 1 1 0 0 1 (-9) =1 1 0 0 0 1 (-1)

overflow

0 1 1 0 1 (13) + 1 1 0 0 0 (-8) = 1 0 0 1 0 1 (5)

1 1 1 0 1 (-13) + 0 1 0 0 0 (8) = 1 0 0 1 0 1 (+5)

Page 17: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

17

Addition and Subtraction

β€’ Two’s complement

0 1 0 1 1 (11) + 0 0 1 1 0 (6) = 1 0 0 0 1 (-15)

0 1 0 1 1 (11) + 0 0 0 1 0 (2) = 0 1 1 0 1 (13)

1 1 1 0 1 (-3) + 1 1 0 1 1 (-5) =1 1 1 0 0 0 (-8)

1 1 0 0 0 (-8) + 1 0 1 1 1 (-9) =1 0 1 1 1 1 (-17)

overflow indicator

overflow indicator

0 1 1 0 1 (13) + 1 1 0 0 0 (-8) = 1 0 0 1 0 1 (5)

1 0 0 1 1 (-13) + 0 1 0 0 0 (8) = 1 1 0 1 1 (-5)

Page 18: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

18

Arithmetic Shift Operations

β€’ For given {π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0}

β€’ Signed-magnitude π‘₯π‘₯π‘›π‘›βˆ’1, 0, 0, … , 0, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 , 0, 0, …

β€’ Two’s complement

π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’1, … , π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 , 0, 0, …

β€’ One’s complement π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’1, … , π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 , π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’1, …

Page 19: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

Supplementary Materials

Page 20: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

20

Arithmetic Shift Operations

β€’ Derivation of the extension of the two’s complement 𝑋𝑋 = π‘‹π‘‹π‘›π‘›βˆ’1…0 = {π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0}

If X>0, it is the same as the signed-magnitude case. If X<0 (if X β‰  -2n),

𝑋𝑋 = π‘‹π‘‹π‘›π‘›βˆ’1…0 = π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 βˆ’π‘‹π‘‹ = {π‘‹π‘‹π‘›π‘›βˆ’1…0 + 𝑒𝑒𝑒𝑒𝑒𝑒0}

(βˆ’π‘‹π‘‹)ext= 00 … 0 π‘‹π‘‹π‘›π‘›βˆ’1…0 + 𝑒𝑒𝑒𝑒𝑒𝑒0 00 … 0 = 00 … 0 𝐾𝐾 00 … 0 βˆ’ βˆ’π‘‹π‘‹ ext = 00 … 0 𝐾𝐾 00 … 0 + π‘’π‘’π‘’π‘’π‘’π‘’βˆ’π‘šπ‘š = 11 … 1 𝐾𝐾� 11 … 1 + π‘’π‘’π‘’π‘’π‘’π‘’βˆ’π‘šπ‘š

= 11 … 1 𝐾𝐾� + 𝑒𝑒𝑒𝑒𝑒𝑒0 00 … 0 = 11 … 1 2𝑛𝑛 βˆ’ 𝐾𝐾 00 … 0 = 11 … 1 2𝑛𝑛 βˆ’ π‘‹π‘‹π‘›π‘›βˆ’1…0 + 𝑒𝑒𝑒𝑒𝑒𝑒0 00 … 0 = 11 … 1 π‘‹π‘‹π‘›π‘›βˆ’1…0 00 … 0

∴ 𝑋𝑋ext = π‘₯π‘₯π‘›π‘›βˆ’1 … π‘₯π‘₯π‘›π‘›βˆ’1 π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 00 … 0

If X=2n, we can directly prove it.

Page 21: Computer Arithmetic Algorithms - WSUdaehyun/teaching/2017_EE466/...Arithmetic Shift Operations β€’ Derivation of the extension of the one’s complement 𝑋𝑋= 𝑋𝑋 π‘›π‘›βˆ’1…0

21

Arithmetic Shift Operations

β€’ Derivation of the extension of the one’s complement 𝑋𝑋 = π‘‹π‘‹π‘›π‘›βˆ’1…0 = {π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0}

If X>0, it is the same as the signed-magnitude case. If X<0,

𝑋𝑋 = π‘‹π‘‹π‘›π‘›βˆ’1…0 = π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 βˆ’π‘‹π‘‹ = {π‘‹π‘‹π‘›π‘›βˆ’1…0}

(βˆ’π‘‹π‘‹)ext= 00 … 0 π‘‹π‘‹π‘›π‘›βˆ’1…0 00 … 0 βˆ’ βˆ’π‘‹π‘‹ ext = 00 … 0 π‘‹π‘‹π‘›π‘›βˆ’1…0 00 … 0 = 11 … 1 π‘‹π‘‹π‘›π‘›βˆ’1…0 11 … 1

∴ 𝑋𝑋ext = π‘₯π‘₯π‘›π‘›βˆ’1 … π‘₯π‘₯π‘›π‘›βˆ’1 π‘₯π‘₯π‘›π‘›βˆ’1, π‘₯π‘₯π‘›π‘›βˆ’2, … , π‘₯π‘₯1, π‘₯π‘₯0 π‘₯π‘₯π‘›π‘›βˆ’1 … π‘₯π‘₯π‘›π‘›βˆ’1