Document Sample

Computer Fundamentals Lecture 3 :Computer Arithmetic 2 Objectives After completing this module you will be able to: Perform basic arithmetic operations using binary number system Explain the use of special memory locations in CPU to keep track of the status of last operation Signed and Unsigned Integers Sign-Magnitude Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 3 Lecture Outline Binary Addition Binary Subtraction Number Representation Overflow & Underflow Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 4 Binary Addition Rules of Binary Addition 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 0, and carry 1 to the next more significant bit 1 + 1 + 1 = 1, and carry 1 to the next more significant bit Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 5 Binary Addition - Examples 101 5 00011010 + 26 + 101 +5 00001100 12 1010 10 00100110 38 Exercise 00010011 + 19 10001 + 11101 00111110 62 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 6 Binary Addition - Examples 1. 10001 + 11101 = ? 2. 1110 + 1111 = ? 3. 101101 + 11001 = ? 4. 10111 + 110101 = ? 5. 1011001 + 111010 = ? 6. 11011 + 1001010 = ? Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 7 Binary Addition- Answers Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 8 Binary Subtraction Rules of Binary Subtraction 0 - 0 = 0 0 - 1 = 1, and borrow 1 from the next more significant bit 1 - 0 = 1 1 - 1 = 0 Just like subtraction in any other base Minuend 10110 Subtrahend -10010 Difference 00100 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 9 Binary Subtraction And when a borrow is needed. Note that the borrow gives us 2 in the current bit position. Try out these subtractions: Exercise: 2 0 2 00110011 51 00100101 37 - 00010110 22 - 00010001 - 17 00010100 20 00011101 29 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 10 Binary Subtraction(Contd.) Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 11 Binary Subtraction - Examples 1011011 − 10010 = ? 100010110 − 1111010 = ? 1010110 − 101010 = ? 101101 − 100111 = ? 1000101 − 101100 = ? 1110110 − 1010111 = ? Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 12 Binary Subtraction - Answers Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 13 Overflow & Underflow Overflow Occurs when the result of an operation is too large to store in the location allocated. 0 1100 12 0 0110 06 1 0010 18 Underflow Occurs when the result of an operation is too small to store in the location allocated. Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 14 Binary Addition with overflow Please add the following two numbers (8 bit format) 1001 0110 + 1111 1001 11000 1111 Since we have only 8 bit format the result has no place to appear. Thus it generates an OVERFLOW. Unless we handle them we get wrong results. Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 15 Binary Addition with overflow (Contd.) In the CPU there are special places to hold these two important information. In computer processors the Carry flag (usually indicated as the C Flag/ C bit) is a single bit in a system status (flag) register It is used to indicate when an arithmetic carry or borrow has been generated out of the most significant bit position. Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 16 Binary Addition In computer processors, the oVerflow flag (sometimes called V flag/ V bit) is usually a single bit in a system status register It is used to indicate when an arithmetic overflow has occurred in an operation. These places in the CPU can be accessed through a program. This means that when we design a program we need to first have an understanding of the extent of the data format that we are going to handle. Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 17 Unsigned and Signed Integers Unsigned Integers : Unsigned integer is either positive or zero value of an integer. Example : The number of integers between 0 and + 127 Signed Integer: signed integer is either negative value or positive value of the integer. Example : The number of integers between - 128 and + 127 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 18 Unsigned and Signed integers (Contd.) Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 19 Sign-Magnitude Sign-Magnitude Representation There are many schemes for representing negative integers with patterns of bits. One scheme is sign-magnitude. It uses one bit (usually the leftmost) to indicate the sign. "0“ - indicates a positive integer "1“ - indicates a negative integer The rest of the bits are used for the magnitude of the number. Eg. -2410 is represented as: 1001 1000 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 20 Sign-Magnitude Sign-Magnitude Representation Sign Bit 0000 1001 1000 1001 +9 -9 Problem: two values for zero 0000 0000 1000 0000 8-bit number can represent from -127 (1111 1111) to +127 (0111 1111) Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 21 Number Representation 001011 +01011 001110 +01110 +11001 011001 001011 +01011 100110 -00110 +00101 000101 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 22 Number Representation Addition 001011 +01011 110110 + -10110 -01011 101011 Subtraction 001011 +01011 001001 - +01001 +00010 000010 Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology 23 Thank You Next Lecture Lecture 04: Complimentary Arithmetic Computer Fundamentals (101) Lecture 03 - Computer Arithmetic © Sri Lanka Institute of Information Technology

DOCUMENT INFO

Shared By:

Tags:

Stats:

views: | 1 |

posted: | 4/13/2012 |

language: | English |

pages: | 23 |

OTHER DOCS BY roshan.iesl

How are you planning on using Docstoc?
BUSINESS
PERSONAL

By registering with docstoc.com you agree to our
privacy policy and
terms of service, and to receive content and offer notifications.

Docstoc is the premier online destination to start and grow small businesses. It hosts the best quality and widest selection of professional documents (over 20 million) and resources including expert videos, articles and productivity tools to make every small business better.

Search or Browse for any specific document or resource you need for your business. Or explore our curated resources for Starting a Business, Growing a Business or for Professional Development.

Feel free to Contact Us with any questions you might have.