Docsity

Computer Architecture: ALU - Digit Sets, Carry-Save, Two's-Complement, and Division - Prof, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download Computer Architecture: ALU - Digit Sets, Carry-Save, Two's-Complement, and Division - Prof and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 1

Part III

The Arithmetic/Logic Unit

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 2

About This Presentation

This presentation is intended to support the use of the textbook Computer Architecture: From Microprocessors to Supercomputers

Oxford University Press, 2005, ISBN 0-19-515455-X. It is updatedregularly by the author as part of his teaching of the upper-divisioncourse ECE 154, Introduction to Computer Architecture, at theUniversity of California, Santa Barbara. Instructors can use theseslides freely in classroom teaching and for other educationalpurposes. Any other use is strictly prohibited. © Behrooz Parhami^ Edition

Released

Revised

Revised

Revised

Revised

First^

July 2003

July 2004

July 2005

Mar. 2006

Jan. 2007

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 4

Computer Arithmetic as a Topic of Study

Graduate courseECE 252B – Text: Computer Arithmetic

Oxford U Press, 2000 Brief overview article – Encyclopedia of Info Systems

Academic Press, 2002,Vol. 3, pp. 317-

Our textbook’s treatmentof the topic falls betweenthe two extremes (4 chap.)

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 5

9 Number Representation

Arguably the most important topic in computer arithmetic:^ • Af

fects system compatibility and ease of arithmetic • Two’s complement, flp, and unconventional methods^ Topics in This Chapter^ 9.^

Positional Number Systems 9.2 Digit Sets and Encodings 9.3 Number-Radix Conversion 9.4 Signed Integers 9.5 Fixed-Point Numbers 9.6 Floating-Point Numbers

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 7

Unsigned Binary Integers

Figure 9.

Schematic representation of 4-bit code for integers in [0, 15].

0000

0001 1111

0010

1110

0011

1101

0100

1100

1000

0101

1011

0110

1010

0111 1001

0 1

(^234567) (^151411) (^1312)

98 Inside: Natural numberOutside: 4-bit encoding^10

Turn^ x^ notchescounterclockwiseto add^ x^1 15203456978 Turn^ y^ notchesclockwiseto subtract^ y (^1413121110)

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 8

Representation Range and Overflow

Figure 9.

Overflow regions in finite number representation systems. For unsigned representations covered in this section,

-^ max

max

Finite set of representable numbers

max Overflow region

Overflow region

Numbers largerthan^ max

Numbers smallerthan^

max

−^

−^

Example 9.2, Part d

Discuss if overflow will occur when computing 3

in a number

system with

k^ = 8 digits in radix

r^ = 10.

Solution The result 86 093 442 is representable in the number system which has a range [0, 99 999 999]; however, if 3

17 is computed en route to

the final result, overflow will occur.

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 10

Carry-Save Numbers

Radix-2 numbers using the digits 0, 1, and 2 Example: (1 0 2 1)

= (1two^

3 × 2 ) + (
2 × 2 ) + (
1 × 2 ) + (
0 × 2 ) = 13

Possible encodings (a) Binary

(b) Unary

01 (First alternate)

10 (Second alternate)

11 (Unused)

MSB^

First bit

LSB^

Second bit

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 11

Figure 9.

Adding a binary number or another

carry-save number to a carry-save number.

The Notion of Carry-Save Addition

Twocarry-saveinputs

Carry-saveinputBinary inputCarry-saveoutput

This bitbeing 1representsoverflow(ignore it)

0

0 0

a. Carry-save addition.

Carry-saveaddition b. Adding two carry-save numbers.

Carry-saveaddition

Digit-set combination: {0, 1, 2} + {0, 1} = {0, 1, 2, 3} = {0, 2} + {0, 1}

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 13

Justifications for Radix Conversion Rules Figure 9.

Justifying one step of the conversion of

x^ to radix 2.

x^^0 x mod 2

Binary representation of

⎣ x /2⎦ Justifying Horner’s rule.

1

2

1 2 0

1

2

1

0

(^

)^

k^

k

k^ k^

r^

k^

k

x^ x

x^

x^ r^

x^ r

x r^

x

−^

−

−^ −^

−^

−

=^

+^

+^ +

L^

L

0

1

2 (^

(^

(^ )))

x^ r x

r x

r

=^

+^

+^

+^ L

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 14

9.4 Signed Integers

-^ We dealt with representing the natural numbers •^ Signed or directed whole numbers = integers^ {... ,

−3,^ −2,

-^ Signed-magnitude representation^ +27 in 8-bit signed-magnitude binary code

–27 in 8-bit signed-magnitude binary code

–27 in 2-digit decimal code with BCD digits 1 0010 0111 • Biased representation Represent the interval of numbers [

− N ,^ P ] by the unsigned

interval [0,

P^ +^ N ]; i.e., by adding

N^ to every number

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 16

Conversion from 2’s-Complement to Decimal

Example 9.

Convert

x^ = (1 0 1 1 0 1 0 1)

2’s-compl^

to decimal.

Solution Given that x is negative, one could change its sign and evaluate –

x.

Shortcut: Use Horner’s rule, but take the MSB as negative–^

×^ 2 + 0
→^ –2^ ×
2 + 1^ →
–3^ ×^ 2 + 1
→^ –^
×^ 2 + 0
→^ –
×^ 2 + 1
→^ –
×^ 2 + 0
→^ –
×^ 2 + 1

→^ –75 Example 9.

Given^ y

, find the representation of –2’s-compl

y.

Solution^ – y^ = (0 1 0 0 1 0 1 0) + 1 = (0 1 0 0 1 0 1 1)

2’s-compl^

(i.e., 75)

Sign Change for a 2’s-Complement Number

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 17

Two’s-Complement Addition and Subtraction

Figure 9.

Add′Sub Binary adder used as 2’s-complement adder/subtractor.

x^ ±^ y

x y

k / k /

k /

y^ or^ y^ ′

c^ in Adder c^ out

k /

Computer Architecture, The Arithmetic/Logic Unit

Schematic representation of 4-bit 2’s-complement

 - Jan. - Slide - Figure 9. Fixed-Point 2’s-Complement Numbers 
    1. encoding for (1 + 3)-bit fixed-point numbers in the range [–1, +7/8].
                1.  - 1. 
                    • 0. - 1. - +0 +. - +.25 +.375 +.5 +.625+.75+. - –.125–.25 –.375 –.5 –.625–.75–.875–

Jan. 2007^

Computer Architecture, The Arithmetic/Logic Unit

Slide 20

Radix Conversion for Fixed-Point Numbers

-^ Perform arithmetic in the new radix

R

Evaluate a polynomial in

–1 r : (. 011)

= 0^ two^

–1^ × 2 + 1
–2^ × 2 + 1
–3 × 2

Simpler: View the fractional part as integer, convert, divide by

l r

(. 011)^ two

= (?)^ ten Multiply by 8 to make the number an integer: (011)

= (3)two^

ten

Thus, (

. 011)^ two

= (. ten 375)ten

-^ Perform arithmetic in the old radix

r

Multiply the given fraction by

R , use the whole part as the MSD

and the fractional part to repeat the process(. 72)^ = (?)ten^

two 0.72^ ×^

2 = 1.44, so the answer begins with 0. 0.44^ ×^

2 = 0.88, so the answer begins with 0. Convert the whole and fractional parts separately.To convert the fractional part from an old radix

r^ to a new radix

R :