arithmetic & logic unit

23
CSCI-365 Computer Organization Lecture Note : Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, ©2005 Some slides and/or pictures in the following are adapted from: slides ©2008 UCB

Upload: ailis

Post on 05-Jan-2016

43 views

Category:

Documents


1 download

DESCRIPTION

Arithmetic & Logic Unit. Does the calculations Everything else in the computer is there to service this unit Handles integers May handle floating point (real) numbers May be separate FPU (maths co-processor) May be on chip separate FPU (486DX +). ALU Inputs and Outputs. Binary Numerals. - PowerPoint PPT Presentation

TRANSCRIPT

Page 1: Arithmetic & Logic Unit

CSCI-365Computer Organization

Lecture

Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson & Hennessy, ©2005 Some slides and/or pictures in the following are adapted from: slides ©2008 UCB

Page 2: Arithmetic & Logic Unit

Arithmetic & Logic Unit

Does the calculations Everything else in the computer is there to

service this unit Handles integers May handle floating point (real) numbers May be separate FPU (maths co-processor) May be on chip separate FPU (486DX +)

Page 3: Arithmetic & Logic Unit

ALU Inputs and Outputs

Page 4: Arithmetic & Logic Unit

Binary Numerals

01101101b Bits are numbered from the right

b7 b6b5b4b3b2b1b0

Subscripts represent the place value bi has place value 2i

Convert to decimal b7 * 27+b6*26 + b5*25 +b4*24 +b3*23 +b2*22 +b1*21 + b0*20

Page 5: Arithmetic & Logic Unit

Decimal to Binary

Decimal number is converted to binary by repeated divisions by 2 record the remainders Stop when you reach 0

Concatenate the remainders The order: first remainder is least significant bit 55d = 110111b

Page 6: Arithmetic & Logic Unit

Binary

1 bit 0 ; 0 1 ; 1

2 bits 00 ; 0 01 ; 1 10 ; 2 11 ;3

•3 bits

•000 ;0

•001 ;1

•010 ;2

•011 ;3

•100 ;4

•101 ;5

•110 ;6

•111 ;7

Page 7: Arithmetic & Logic Unit

4 bits and Hex

0000 ;0

0001 ;1

0010 ;2

0011 ;3

0100 ;4

0101 ;5

0110 ;6

0111 ;7

1000 ;8

1001 ;9

1010 ;10 (Ah)

1011 ;11 (Bh)

1100 ;12 (Ch)

1101 ;13 (Dh)

1110 ;14 (Eh)

1111 ;15 (Fh)

Page 8: Arithmetic & Logic Unit

Binary to Hex

Group bits by fours (from right to left, starting with least significant bits)

Add zeros as necessary to complete the last group

Convert each group to the equivalent hex digit (look up the previous table)

Ex: 0101 1110b = 5Eh

Page 9: Arithmetic & Logic Unit

Hex to Binary

Expand each hex digit to the equivalent 4-bit binary form

The leading zeros of leftmost digit can be omitted

36h = 0011 0110b (or 110110b)

Page 10: Arithmetic & Logic Unit

Binary Storage

A pre-arranged storage size is used typically byte, word, doubleword, or quadword at least 8 bits will be required encode the bits Ex: 65d is 0100 0001b

Page 11: Arithmetic & Logic Unit

Unsigned Byte

all 8 bits used to represent the magnitude of the number

Minimum 0 (zero) is coded as 00000000b Maximum 255 is coded as 11111111b

Page 12: Arithmetic & Logic Unit

Singed Byte

two’s complement code is most common only 7 bits are used for the magnitude Minimum -128 is coded as 10000000b Maximum +127 is coded as 01111111b Zero is 00000000b Note that we can not read 10000001 as -1.

Page 13: Arithmetic & Logic Unit

Negative Numbers

Remember -x’s 2 complement code is the same as 2n-x.

Change Sign Rule Flip all the bits Add 1

Page 14: Arithmetic & Logic Unit

Geometric Depiction of Twos Complement Integers

Page 15: Arithmetic & Logic Unit

How Does Change Sign Rule Come From

The 2’s Complement codes for x and -x add to a power of 2 8-bit code: c+(-c)=28

16-bit code: c+(-c)=216

(-c)=2n-c=[(2n-1)-c]+1

=[(2n-1) + (-c)]+1 Note that (2n-1) is 1111..1b Flip and Plus 1

Page 16: Arithmetic & Logic Unit

Benefits

One representation of zero Arithmetic works easily (see later) Negating is fairly easy

3 = 00000011 Boolean complement gives 11111100 Add 1 to LSB 11111101

Page 17: Arithmetic & Logic Unit

Two’s Compliment

+3 = 00000011 +2 = 00000010 +1 = 00000001 +0 = 00000000 -1 = 11111111 -2 = 11111110 -3 = 11111101

Page 18: Arithmetic & Logic Unit

Can We Read 2’s Complement Code Easily?

Positive ones: yes

00110111b(37h) --->55d Negative ones: No!

11001001b (C9h) ---> not -49h by Change Signed rule -55d double check, the code should be the same as 201d ‘s code

201d = 11001001b

since -55+ 256 = 201

Page 19: Arithmetic & Logic Unit

Conversion Between Lengths

Positive number pack with leading zeros +18 = 00010010 +18 = 00000000 00010010 Negative numbers pack with leading ones -18 = 11101110 -18 = 11111111 11101110 i.e. pack with MSB (sign bit)

Page 20: Arithmetic & Logic Unit

Unsigned Addition

Numbers can be added in any number base Use the same algorithm you practiced in second grade!

Binary Example: c c c

10101

+ 0111

11100

Page 21: Arithmetic & Logic Unit

Hex Addition

Hex Example: c c

2CF03

+435C8

704CB A carry occurs when the sum is sixteen or

greater

Page 22: Arithmetic & Logic Unit

Unsigned Subtraction

Borrows are worth two sometimes you need to borrow from afar! b b b b

11000011

- 1101001

01011010

Page 23: Arithmetic & Logic Unit

Hex Subtraction

A borrow is worth of 16 Example: b b

FCF03

-435C9

B993A