240 likes | 561 Views
CHAPTER 9 COMPUTER ARITHMETIC - ALU. CSNB123 coMPUTER oRGANIZATION. Expected Course Outcome. Overview. ALU. Part of the computer that do the arithmetic and logical operation on data Simple digital logic devices that can; S tore binary digits Perform simple BOOLEAN logic operations.
E N D
CHAPTER 9 COMPUTER ARITHMETIC - ALU CSNB123 coMPUTERoRGANIZATION Systems and Networking
Expected Course Outcome Systems and Networking
Overview 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 Systems and Networking
ALU Interconnection Systems and Networking
ALU and Registers CPU Registers Arithmetic Logic Unit (ALU) Internal CPU Interconnection Control Unit 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 Systems and Networking
Sign Magnitude Representation 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 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 Systems and Networking
Twos complements representation 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 Systems and Networking
Twos Complements Representation (Cont.) • Negative – sign bit = 1 • Example: • -1 = 11111111 • -2 = 11111110 • -3 = 11111101 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 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 Systems and Networking
Twos Complements Representation – Special Case • Example: 0, consider an 8-bit representation 0 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 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 Systems and Networking
Twos Complements Representation – Conversion between lengths Positive Negative Pack with leading ones 8-bits +18 = 11101110 16-bits -18 = 11111111 11101110 • Pack with leading zeros • 8-bits • +18 = 00010010 • 16-bits • -18 = 00000000 00010010 Systems and Networking
Twos Complements Representation - Operations • Addition • Subtraction 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 Systems and Networking
Twos Complements Representation - Operations Subtraction • Do subtraction via addition 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 Systems and Networking
Additional Reference • William Stallings, Computer Organization and Architecture: Designing for Performance, 8th. Edition, Prentice-Hall Inc., 2010 Systems and Networking
This teaching material is belongs to Systems and Networking Department College of Information Technology UniversitiTenagaNasional (UNITEN) Malaysia 2014 Systems and Networking