Semester Transition Point. EE 109 Unit 11 Binary Arithmetic. Binary Arithmetic ARITHMETIC

Similar documents
EE 109 Unit 6 Binary Arithmetic

10.1. Unit 10. Signed Representation Systems Binary Arithmetic

SIGNED AND UNSIGNED SYSTEMS

Binary Addition. Add the binary numbers and and show the equivalent decimal addition.

2.1. Unit 2. Integer Operations (Arithmetic, Overflow, Bitwise Logic, Shifting)

CHAPTER V NUMBER SYSTEMS AND ARITHMETIC

Decimal & Binary Representation Systems. Decimal & Binary Representation Systems

Number System. Introduction. Decimal Numbers

Chapter 10 Binary Arithmetics

BINARY SYSTEM. Binary system is used in digital systems because it is:

1010 2?= ?= CS 64 Lecture 2 Data Representation. Decimal Numbers: Base 10. Reading: FLD Digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

Chapter 3: part 3 Binary Subtraction

Basic Definition INTEGER DATA. Unsigned Binary and Binary-Coded Decimal. BCD: Binary-Coded Decimal

CO Computer Architecture and Programming Languages CAPL. Lecture 9

Digital Arithmetic. Digital Arithmetic: Operations and Circuits Dr. Farahmand

CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS

Arithmetic Operations on Binary Numbers

COMP Overview of Tutorial #2

A complement number system is used to represent positive and negative integers. A complement number system is based on a fixed length representation

Lecture Topics. Announcements. Today: Integer Arithmetic (P&H ) Next: continued. Consulting hours. Introduction to Sim. Milestone #1 (due 1/26)

Chapter 1. Digital Systems and Binary Numbers

Number Systems. Readings: , Problem: Implement simple pocket calculator Need: Display, adders & subtractors, inputs

Digital Fundamentals. CHAPTER 2 Number Systems, Operations, and Codes

Chapter 1 Review of Number Systems

CS 64 Week 1 Lecture 1. Kyle Dewey

Part 2,Number Systems Questions

MC1601 Computer Organization

Computer Organization

Lecture 8: Addition, Multiplication & Division

Chapter 4 Arithmetic Functions

COMP 122/L Lecture 2. Kyle Dewey

World Inside a Computer is Binary

Binary Addition & Subtraction. Unsigned and Sign & Magnitude numbers

Number Systems Base r

ECE/Comp Sci 352 Digital Systems Fundamentals. Charles R. Kime Section 2 Fall Logic and Computer Design Fundamentals

CS 121 Digital Logic Design. Chapter 1. Teacher Assistant. Hadeel Al-Ateeq

CS & IT Conversions. Magnitude 10,000 1,

CO212 Lecture 10: Arithmetic & Logical Unit

EE292: Fundamentals of ECE

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

Disassembly of MC9S12 op codes Decimal, Hexadecimal and Binary Numbers

DIGITAL ARITHMETIC: OPERATIONS AND CIRCUITS

Computer (Literacy) Skills. Number representations and memory. Lubomír Bulej KDSS MFF UK

Arithmetic Processing

CHW 261: Logic Design

Arithmetic Operations

Chapter 3: Arithmetic for Computers

Number representations

COMPUTER ARITHMETIC (Part 1)

INF2270 Spring Philipp Häfliger. Lecture 4: Signed Binaries and Arithmetic

carry in carry 1101 carry carry

Signed Binary Numbers

Digital Systems and Binary Numbers

Number Systems. Decimal numbers. Binary numbers. Chapter 1 <1> 8's column. 1000's column. 2's column. 4's column

Logic Circuits I ECE 1411 Thursday 4:45pm-7:20pm. Nathan Pihlstrom.

2. MACHINE REPRESENTATION OF TYPICAL ARITHMETIC DATA FORMATS (NATURAL AND INTEGER NUMBERS).

Goals for this Week. CSC 2400: Computer Systems. Bits, Bytes and Data Types. Binary number system. Finite representations of binary integers

Module 2: Computer Arithmetic

Number Systems Standard positional representation of numbers: An unsigned number with whole and fraction portions is represented as:

Chapter 5: Computer Arithmetic. In this chapter you will learn about:

CS 31: Introduction to Computer Systems. 03: Binary Arithmetic January 29

4/8/17. Admin. Assignment 5 BINARY. David Kauchak CS 52 Spring 2017

COE 202: Digital Logic Design Number Systems Part 2. Dr. Ahmad Almulhem ahmadsm AT kfupm Phone: Office:

Chapter 2 Bits, Data Types, and Operations

Fundamentals of Programming Session 2

Learning Objectives. Binary over Decimal. In this chapter you will learn about:

Binary Representations and Arithmetic

Operations On Data CHAPTER 4. (Solutions to Odd-Numbered Problems) Review Questions

Groups of two-state devices are used to represent data in a computer. In general, we say the states are either: high/low, on/off, 1/0,...

CS/COE0447: Computer Organization

CS/COE0447: Computer Organization

Positional Number System

Harry H. Porter, 2006

Chapter 2 Bits, Data Types, and Operations

Chapter 2 Bits, Data Types, and Operations

DLD VIDYA SAGAR P. potharajuvidyasagar.wordpress.com. Vignana Bharathi Institute of Technology UNIT 1 DLD P VIDYA SAGAR

ET355 Microprocessors Thursday 6:00 pm 10:20 pm

Inf2C - Computer Systems Lecture 2 Data Representation

Chapter 2: Number Systems

T02 Tutorial Slides for Week 2

CS 31: Intro to Systems Binary Arithmetic. Kevin Webb Swarthmore College January 26, 2016

Chapter 3: Number Systems and Codes. Textbook: Petruzella, Frank D., Programmable Logic Controllers. McGraw Hill Companies Inc.

Experiment 7 Arithmetic Circuits Design and Implementation

Chapter 10 - Computer Arithmetic

Arithmetic and Logical Operations

Numerical Representations On The Computer: Negative And Rational Numbers

Topic Notes: Bits and Bytes and Numbers

9/23/15. Agenda. Goals of this Lecture. For Your Amusement. Number Systems and Number Representation. The Binary Number System

Chapter 4. Operations on Data

Number Systems. Both numbers are positive

Arithmetic for Computers

Numerical Representations On The Computer: Negative And Rational Numbers

Microcomputers. Outline. Number Systems and Digital Logic Review

Lecture 2: Number Systems

COMP2611: Computer Organization. Data Representation

Princeton University Computer Science 217: Introduction to Programming Systems. Goals of this Lecture. Number Systems and Number Representation

Number Systems CHAPTER Positional Number Systems

Principles of Computer Architecture. Chapter 3: Arithmetic

Topic Notes: Bits and Bytes and Numbers

Chapter 5: Computer Arithmetic

Transcription:

1 2 Semester Transition Point EE 109 Unit 11 Binary Arithmetic At this point we are going to start to transition in our class to look more at the hardware organization and the low-level software that is produced by compilers This is where HW really meets SW We need to finish off some topics of how the HW carries out operations on numbers 3 4 Binary Arithmetic ARITHMETIC Can perform all arithmetic operations (+,-,*, ) on binary numbers Can use same methods as in decimal Still use carries and borrows, etc. Only now we carry when sum is 2 or more rather than 10 or more (decimal) We borrow 2 s not 10 s from other columns Easiest method is to add bits in your head in decimal (1+1 = 2) then convert the answer to binary (2 10 = 10 2 )

5 6 Binary Addition Binary Addition & Subtraction In decimal addition we carry when the sum is 10 or more In binary addition we carry when the sum is 2 or more Add bits in binary to produce a sum bit and a carry bit 0 1 1 1 + 0 0 1 1 1 0 1 0-0 1 0 1 0 0 1 1 1 + 0 + 1 + 0 + 1 00 01 01 10 no need to carry sum bit no need to carry sum bit no need to carry sum bit carry 1 into next column of bits sum bit 7 8 Binary Multiplication Like decimal multiplication, find each partial product and shift them, then sum them up Multiplying two n-bit numbers yields at most a -bit product 0 1 1 0 * 0 1 0 1 Hexadecimal Arithmetic Same style of operations Carry when sum is 16 or more, etc. 4 D 16 + B 5 16

9 Taking the Negative 10 Given a number in signed magnitude or 2 s complement how do we find its negative (i.e. -1 * X) Signed Magnitude: "Taking the 2's complement" SUBTRACTION THE EASY WAY 2 s complement: Operation defined as: 1. 2. 11 12 Taking the 2 s Complement Taking the 2 s Complement Invert (flip) each bit (take the 1 s complement) 1 s become 0 s 0 s become 1 s Add 1 (drop final carry-out, if any) -32 16 8 4 2 1 010011 Original number = +19 Bit flip is called the 1 s complement of a number Resulting number = -19 1-32 16 8 4 2 1 2 Original number = 101010 Take the 2 s complement yields the negative of a number Resulting number = Back to original = 3 0000 1000 Original # = 0 Take the 2 s complement 2 s comp. of 0 is Original # = -8 Take the 2 s complement Negative of -8 is Important: Taking the 2 s complement is equivalent to taking the negative (negating) (i.e. no positive equivalent, but this is not a huge problem)

2 s Complement System Facts Normal binary place values but MSB has negative weight MSB determines sign of the number 0 = positive / 1 = negative Special Numbers 0 = All 0 s (00 00) -1 = All 1 s (11 11) Max Positive = 0 followed by all 1 s (011..11) Max Negative = 1 followed by all 0 s (100 00) To take the negative of a number (e.g. -7 => +7 or +2 => -2), requires taking the complement 2 s complement of a # is found by flipping bits and adding 1 1001 0110 + 1 0111 x = -7 Bit flip (1 s comp.) Add 1 -x = -(-7) = +7 13 2 s Complement Addition/Subtraction Addition Sign of the numbers do not matter Subtraction Any subtraction (A-B) can be converted to by (A-B) becomes Drop any carry-out 14 2 s Complement Addition 15 Unsigned and Signed Addition 16 No matter the sign of the operands just add as normal Drop any extra carry out 0011 + 0010 + 0010 Addition process is the same for both unsigned and signed numbers Add columns right to left Examples: 0011 + 1110 + 1110 1001 + 0011

2 s Complement Subtraction Take the 2 s complement of the subtrahend and add to the original minuend Drop any extra carry out 0011(+3) - 0010(+2) (-3) - 1110(-2) 17 Unsigned and Signed Subtraction Subtraction process is the same for both unsigned and signed numbers Convert A B to A + 2 s Comp. of B Drop any final carry out Examples: 18 1100-0010 Important Note 19 20 Almost all computers use 2's complement because The same addition and subtraction can be used on unsigned and 2's complement (signed) numbers Thus we only need to perform operations on both unsigned and signed numbers OVERFLOW

21 22 Overflow Unsigned Overflow Overflow occurs when the result of an arithmetic operation is Conditions and tests to determine overflow depend on 10 + 7 = 17 With 4-bit unsigned numbers we can only represent 0 15. Thus, we say overflow has occurred. Overflow occurs when you cross this discontinuity +12 +14 +13 1100 1011 +11 +10 1110 1010 +15 +9 1111 Plus 7 1001 10 0 0000 1000 +8 +1 0001 +2 0010 0011 +3 0100 +4 0101 +5 0110 0111 +6 +7 23 24 2 s Complement Overflow Overflow in Addition 5 + 7 = +12-6 + -4 = -10 With 4-bit 2 s complement numbers we can only represent -8 to +7. Thus, we say overflow has occurred. -4-3 -5-2 1100 1011-6 1110 1010-1 -7 1111 1001 0 0000 1000-8 0001 0111 +1 +7 0010 0110 0011 +2 0101 0100 +6 +3 +5 +4 Overflow occurs when the result of the addition cannot be represented with the given number of bits. Tests for overflow: Unsigned: Signed: + 0100 0110 + 0101 Overflow occurs when you cross this discontinuity

Overflow in Subtraction 25 26 Overflow occurs when the result of the subtraction cannot be represented with the given number of bits. Tests for overflow: Unsigned: Signed: 0111-1000 TRANSLATING SIGNED OR UNSIGNED HEXADECIMAL Translating Hexadecimal 27 Taking the 16 s Complement 28 Hex place values (16 2, 16 1, 16 0 ) can ONLY be used if the number is If hex represents unsigned binary 1. B2 hex = If hex represents signed value (2 s comp.) 1. 2. 3. Hex Binary Sign 0 = 0000 = Pos. 1 = 0001 = Pos. 2= 0010 = Pos. 3 = 0011 = Pos. 4 = 0100 = Pos. 5 = 0101 = Pos. 6 = 0110 = Pos. 7 = 0111 = Pos. 8 = 1000 = Neg. 9 = 1001 = Neg. A = 1010 = Neg. B = 1011 = Neg. C = 1100 = Neg. D = = Neg. E = 1110 = Neg. F = 1111 = Neg. Taking the 2 s complement of a binary number yields its negative and is accomplished by taking the complement (bit flip) and adding 1 Taking the 16 s complement of a hex number yields its negative and is accomplished by finding the 15 s complement and adding 1 15 s complement is found by subtracting each digit of the hex number from 16 Original value B2: 16 s comp. of B2:

Translating Hexadecimal Given 6C hex If it is unsigned: 6C hex = If it is signed Determine the sign by looking at MSD 0-7 hex has a in the MSB [i.e. ] 8-F hex has a in the MSB [i.e. ] Thus, 6C is 6C hex = 29 Translating Hexadecimal Given B2 hex If it is unsigned B2 hex = If it is signed Determine the sign: Take the 16 s complementand apply hex place values to find the neg. number s magnitude 30 Finding the Value of Hex Numbers 31 Hex Addition and Overflow 32 8A hex representing a signed (2 s comp.) value Step 1: Determine the sign: Step 2: Take the 16 s comp. to find magnitude Step 3: Apply hex place values ( 16 = 10 ) Step 4: Final value: B2 hex = 10 7C hex representing a signed (2 s comp.) value Step 1: Determine the sign: Step 2: Apply hex place values (7C 16 = 10 ) 7C hex representing an unsigned value = 10 Same rules as in binary Add left to right Drop any carry (carry occurs when sum > F 16 ) Same addition overflow rules Unsigned: Signed: 7AC5 + C18A 6C12 + 549F

Hex Subtraction and Overflow 33 Same rules as in binary Convert A B to A + Comp. of B Drop any final carry out Same subtraction overflow rules Unsigned: Signed: B1ED - 76FE 0001-0002