CHAPTER 9 COMPUTER ARITHMETIC - ALU CSNB123 coMPUTER oRGANIZATION NSMS2013 Ver.1 Systems and Networking
Overview NSMS2013 Ver.1 Systems and Networking Arithmetic Logic Unit (ALU) Focus on – computer arithmetic Logic function Support 2 types of number Integer Floating-point Component in processor NSMS2013 Ver.1 Systems and Networking
ALU Part of the computer that do the arithmetic and logical operation on data Simple digital logic devices that can; Store binary digits Perform simple BOOLEAN logic operations CPU Registers Arithmetic Logic Unit (ALU) Internal CPU Interconnection Control Unit NSMS2013 Ver.1 Systems and Networking
Systems and Networking ALU Interconnection NSMS2013 Ver.1 Systems and Networking
ALU and Registers CPU Component Description Registers Present data to ALU Store result of an operation Temporary storage locations within the processor that are connected by signal paths to the ALU ALU set flags – result of an operation – store in registers Control unit Provides signals that control; Operation of the ALU Movement of the data into and out of the ALU CPU Registers Arithmetic Logic Unit (ALU) Internal CPU Interconnection Control Unit NSMS2013 Ver.1 Systems and Networking
Integer Representation Computer - logic circuits - operate on information; 0 and 1 two values electrical signals – bit How to represent negative value in binary? Sign-magnitude representation Twos complements representation NSMS2013 Ver.1 Systems and Networking
Sign Magnitude Representation NSMS2013 Ver.1 Systems and Networking
Sign-magnitude Representation Ways of presenting -ve and +ve integers The most significant (leftmost) bits in the word as a sign bit Example: if the sign bit is 0 then the number is +ve, vice versa Hence sign magnitude representation employed sign bit NSMS2013 Ver.1 Systems and Networking
Sign-magnitude Representation (Cont.) Example +18 = 00010010 -18 =10010010 Rarely used Drawbacks; Addition/subtraction require a consideration of both the signs of the numbers and their relative magnitudes to carry out the required operation 2 representation of 0; +010 = 00000000 -010 = 10000000 NSMS2013 Ver.1 Systems and Networking
Twos complements representation NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation Used the most significant bit (MSB) as a sign bit (similar to sign magnitude) Differs – the other bits are interpreted Example: +3 = 00000011 +2 = 00000010 +1 = 00000001 +0 = 00000000 NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation (Cont.) Negative – sign bit = 1 Example: -1 = 11111111 -2 = 11111110 -3 = 11111101 NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation (Cont.) Steps for negative integers. Example: -3 +3 = 00000011 11111100 1 11111101 Step 1: Take +ve value Step 2: Boolean Complement Step 3: Add 1 to LSB Result NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation (Cont.) Example: 11110000 11110000 00001111 1 00010000 00010000 = 16 -16 Step 1: Take value Step 2: Boolean Complement Step 3: Add 1 to LSB Result Convert into decimal Put –ve sign NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation – Special Case Example: 0, consider an 8-bit representation 11111111 1 100000000 Step 1: Take value Step 2: Boolean Complement Step 3: Add 1 to LSB Result 1 carry out at most significant bit (MSB) - Ignored hence -0 = 0 NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation – Range of Numbers 8-bit 2s complement +127 = 0111 1111 -127 = 1000 0000 16-bit 2s complement +32767 = 01111111 11111111 -32767 = 10000000 00000000 NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation – Conversion between lengths Positive Negative Pack with leading zeros 8-bits +18 = 00010010 16-bits -18 = 00000000 00010010 Pack with leading ones 8-bits +18 = 11101110 16-bits -18 = 11111111 11101110 NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation - Operations Addition Subtraction NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation - Operations Addition Addition follows as if the two numbers were unsigned integers (positive or zero) Overflow – result is larger than word ALU provide signals NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation - Operations Subtraction Do subtraction via addition NSMS2013 Ver.1 Systems and Networking
Twos Complements Representation - Operations OVERFLOW RULE If two numbers are added, and they BOTH are POSITIVE or BOTH NEGATIVE, Then OVERFLOW occurs if and only if the RESULT has the OPPOSITE SIGN NSMS2013 Ver.1 Systems and Networking