Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.

Similar presentations


Presentation on theme: "CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson."— Presentation transcript:

1 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

2 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 +)

3 ALU Inputs and Outputs

4 Binary Numerals 01101101b Bits are numbered from the right b 7 b 6 b 5 b 4 b 3 b 2 b 1 b 0 Subscripts represent the place value b i has place value 2 i Convert to decimal b 7 * 2 7 +b 6 *2 6 + b 5 *2 5 +b 4 *2 4 +b 3 *2 3 +b 2 *2 2 +b 1 *2 1 + b 0 *2 0

5 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

6 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

7 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)

8 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

9 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)

10 Binary Addition 0+0 = 0 0+1 = 1 1+0 = 1 1+1 = 10 1+1+1 = 11 001 + 011 = 100

11 Character Data ASCII: American Standard Code for Information Interchange a 7-bit binary code for a set of 128 characters Ex: ‘ A ’ : 41h, 65d, 0100 0001b (how to convert?) usually occupy a byte of storage leading bit may be ignored or used differently by various programs a sequence of bytes containing ASCII codes is referred to as an ASCII string

12 Numeric Data Binary storage 23d: 0001 0111 ASCII storage sequence of ASCII bytes representing the digits of the number 23: ‘ 2 ’ ‘ 3 ’ 00000010 00000011

13 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

14 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

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

16 Negative Numbers Remember -x ’ s 2 complement code is the same as 2 n -x. Change Sign Rule Flip all the bits Add 1

17 Geometric Depiction of Twos Complement Integers

18 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)=2 8 16-bit code: c+(-c)=2 16 (-c)=2 n -c=[(2 n -1)-c]+1 =[(2 n -1) + (-c)]+1 Note that (2 n -1) is 1111..1b Flip and Plus 1

19 Benefits One representation of zero Arithmetic works easily (see later) Negating is fairly easy 3 = 00000011 Boolean complement gives11111100 Add 1 to LSB11111101

20 Two ’ s Compliment +3 = 00000011 +2 = 00000010 +1 = 00000001 +0 = 00000000 -1 = 11111111 -2 = 11111110 -3 = 11111101

21 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

22 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)

23 Converting Signed Data 00111000b Leading zero indicates value is positive simply convert to decimal 38h = 56d Data: +56

24 Converting Signed Data 11001000b Leading one indicates value is negative apply change sign rule, then convert to decimal 00111000b 38h = 56d Data: -56d Note that it is not -48h.

25 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

26 Hex Addition Hex Example: c c 2CF03 +435C8 704CB A carry occurs when the sum is sixteen or greater

27 Unsigned Subtraction Borrows are worth two sometimes you need to borrow from afar! b b b b 11000011 - 1101001 01011010

28 Hex Subtraction A borrow is worth of 16 E xample: b b FCF03 -435C9 B993A


Download ppt "CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson."

Similar presentations


Ads by Google