Docsity

The Arithmetic Logic Unit – Introduction to Computer Architecture | ECE 154, Study notes of Electrical and Electronics Engineering

Partial preview of the text

Download The Arithmetic Logic Unit – Introduction to Computer Architecture | ECE 154 and more Study notes Electrical and Electronics Engineering in PDF only on Docsity!

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 1

Part III

The Arithmetic/Logic Unit

Jan. 2009^

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. 2008

Jan. 2009

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 4

Preview of Arithmetic Unit in the Data Path Fig. 13.^

Key elements of the single-cycle MicroMIPS data path.

/

ALU^

Datacache

Next addr^ Instrcache

Regfile jta inst imm opfn rs^

(rs) (rt)

Dataaddr Datain (^01) ALUSrcALUFunc

DataReadDataWrite

SE

RegInSrc

rt rd RegDstRegWrite

(^32) / 16

Register input

Dataout

ALUOvfl Ovfl Func

(^01231)

Incr PC Next PC

(PC) Br&Jump

ALUout

PC

Registerwriteback^012

Instruction fetch

Reg access / decode

ALU operation

Data access

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 5

Computer Arithmetic as a Topic of Study

Graduate courseECE 252B – Text: Computer Arithmetic

Oxford U Press, 2000nd^ (2ed., late 2009) 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. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 7

9.1 Positional Number Systems

Representations of natural numbers {0, 1, 2, 3, …}^ ||||| ||||| ||||| ||||| ||||| ||

sticks or

unary^

code

radix-10 or

decimal

code

radix-2 or

binary

code

XXVII^

Roman numerals

Fixed-radix positional representation with

k^ digits

Value of a number:

x^ = ( x

x... k –1 k –^

xx )=^10 r^

i Σ x r i

For example:27 = (11011)

= (1two^

4 × 2 ) + (
3 × 2 ) + (
2 × 2 ) + (
1 × 2 ) + (
0 × 2 )

Number of digits for [0,

P ]:^ k^

=^ ⎡log r^

( P^ + 1)

⎤^ =^ ⎣log k –1^ i =0 P ⎦^ + 1 r^

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 8

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. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 10

9.2 Digit Sets and Encodings Conventional and unconventional digit sets • Decimal digits in [0, 9]; 4-bit BCD, 8-bit ASCII • Hexadecimal, or hex for short: digits 0-9 & a-f • Conventional ternary digit set in [0, 2]Conventional digit set for radix

r^ is [0,

r^ – 1]

Symmetric ternary digit set in [–1, 1] • Conventional binary digit set in [0, 1]Redundant digit set [0, 2], encoded in 2 bits( 0 2 1 1 0 )

and ( 1 0 1 0 2 )two^

represent 22two^

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 11

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. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 13

9.3 Number Radix Conversion

-^ Perform arithmetic in the new radix

R

Suitable for conversion from radix

r^ to radix 10

Horner’s rule:^ ( xxk –

...^ k – xx )= (…((0 +^10 r^

x ) r^ + k –^

x ) r^ +... + k –

x ) r^ +^1 x^0

= 0 + 1two^

→^1 ×^
2 + 0^ →
2 ×^ 2 + 1
→^5 ×^
2 + 1^ →
11 ×^ 2 + 0
→^22
×^ 2 + 1
→^45
×^ 2 + 0
→^90
×^ 2 + 1
→^181

-^ Perform arithmetic in the old radix

r

Suitable for conversion from radix 10 to radix

R

Divide the number by

R , use the remainder as the LSD and the quotient to repeat the process 19 / 3^ →^

rem 1, quo 6 / 3

→^ rem 0, quo 2 / 3

→^ rem 2, quo 0

Thus, 19 = (2 0 1)

three

Two ways to convert numbers from an old radix

r^ to a new radix

R

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 14

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. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 16

Two’s-Complement Representation

Figure 9.

Schematic representation of 4-bit 2’s-complement code for integers in [–8, +7].

(^0000 )

0010

1110

0011

1101

0100

1100

1000

0101

1011

0110

1010

0111 1001

+0^ +

+2 +3 +4 +5 +6+ –1 –2 –3 –4 –5 –6–7–

_^

Turn^ x^ notchescounterclockwiseto add^ x^1 –1^2 –2^03 –3–4^4 –5^5 –6^6 –7^7 –8 Turn 16^ –^ y^ notchescounterclockwise toadd^ – y^ (subtract^ y )

With^ k^

bits, numbers in the range [–

k –1^ k –1, 2

  • 1] represented.

Negation is performed by inverting all bits and adding 1.

Jan. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 17

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. 2009^

Computer Architecture, The Arithmetic/Logic Unit

Slide 19

9.5 Fixed-Point Numbers

Positional representation:

k^ whole and

l^ fractional digits

Value of a number:

x^ = ( xk

x^.. .–1 k –^

xx.^ x^10 –

x...^ –^

x )=^ Σ– l^ r^

i x r (^) i

For example:^ 2.375 = (

. 011)^ two

= (1×^2
1 ) + (0×
−^1 × 2 ) + (
−^2 × 2 ) + (
−^3 × 2 )

Numbers in the range [0,

k^ r –^ ulp ] representable, where

ulp^ =^ r

  • l

Fixed-point arithmetic same as integer arithmetic^ (radix point implied, not explicit) Two’s complement properties (including sign change) hold here as well: (01. 011)

2’s-compl^

= (–0×^2
1 ) + (1×
–1^ × 2 ) + (
–2^ × 2 ) + (
–3^ × 2 ) = +
.^375

2’s-compl^

= (–1×^2
1 ) + (1×
–1^ × 2 ) + (
–2^ × 2 ) + (
–3^ × 2 ) = –
.^625

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–