EECC201 Freshman Seminar Intro to Micro controller Dr. Ken Hsu WEEK 7 ADDITION, SUBTRACTION AND COMPARE OF BINARY NUMBERS Important: Irritant sounds may.

Slides:



Advertisements
Similar presentations
Full Adder Display. Topics A 1 bit adder with LED display Ripple Adder Signed/Unsigned Subtraction Hardware Implementation of 4-bit adder.
Advertisements

Combinational Circuits. Analysis Diagram Designing Combinational Circuits In general we have to do following steps: 1. Problem description 2. Input/output.
Lab 10 : Arithmetic Systems : Adder System Layout: Slide #2 Slide #3 Slide #4 Slide #5 Arithmetic Overflow: 2’s Complement Conversions: 8 Bit Adder/Subtractor.
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Addition and Subtraction. Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement.
2’s Complement Arithmetic (remember it’s a fixed length system)
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3: IT Students.
Assembly Language :CSC 225 (Lec#4: Flag Register and Conditional Statements) By Dr. Syed Noman.
Adding and Subtracting Fractions with Like Denominators.
Number Systems Discussion D4.1 Appendix C. Number Systems Counting in Binary Positional Notation Hexadecimal Numbers Negative Numbers.
Major Numeric Data Types Unsigned Integers Signed Integer Alphanumeric Data – ASCII & UNICODE Floating Point Numbers.
Assembly Language and Computer Architecture Using C++ and Java
Signed Numbers Up till now we've been concentrating on unsigned numbers. In real life we have to represent signed numbers ( like: -12, -45, 78). The difference.
Assembly Language and Computer Architecture Using C++ and Java
Negative Numbers Module M3.3 Section 2.4. Negative Numbers Subtract by adding ’s complement Ignore carry.
1 Lecture 2: Number Systems Binary numbers Base conversion Arithmetic Number systems  Sign and magnitude  Ones-complement  Twos-complement Binary-coded.
Chapter 3 Data Representation part2 Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2010.
ADDING INTEGERS Positive + Positive = Positive Positive + Positive = Positive ( +3) + (+2) = +5 ( +3) + (+2) = +5 When a number is positive, you do not.
Binary Addition Addition Rules: = = = = = carry 1 1 carry 1 Example 1: Example 2:
Chapter3 Fixed Point Representation Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
Computer Organization & Programming Chapter2 Number Representation and Logic Operations.
© Janice Regan, CMPT 128, Jan CMPT 128: Introduction to Computing Science for Engineering Students Integer Data representation Addition and Multiplication.
Simple Data Type Representation and conversion of numbers
#1 Lec # 2 Winter EECC341 - Shaaban Positional Number Systems A number system consists of an order set of symbols (digits) with relations.
Computer Architecture
1.11, 1.12, 1.13, 1.14, 1.18, 1.20, 1.23, 1.24, 1.25, 1.32, 1.33.
Complement Numbers. Outline  Negative Numbers Representation  Sign-and-magnitude  1s Complement  2s Complement  Comparison of Sign-and-Magnitude.
6 x 99 Think: round off 99 to 100 So… 6 x 99 becomes 6 x 100 = 600 Then subtract: 600 – 6 = x 79 4 x 80 = 320 – 4 = 316.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
ECEN 248 Lab 4: Multiplexer Based Arithmetic Logic Unit
Operations on Bits Arithmetic Operations Logic Operations
Princess Sumaya Univ. Computer Engineering Dept. Chapter 3:
Chapter 3 Complements Dr. Bernard Chen Ph.D. University of Central Arkansas Spring 2009.
1 Arithmetic and Logic Operations Patt and Patel Ch. 2 & 3.
Combinational Circuits
1 CSC 143 Two' s complement. 2 10's complement  How to represent negative numbers?  Use a sign → but −0 is the same as +0  10's complement  Example.
Notes Over 8 – 5 Add. + Add the whole numbers. Add the fractions and reduce if needed.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Monday, January 13 CEC 220 Digital Circuit Design Slide 1 of 14.
Outline Binary Addition 2’s complement Binary Subtraction Half Adder
Introduction * Binary numbers are represented with a separate sign bit along with the magnitude. * For example, in an 8-bit binary number, the MSB is.
CEC 220 Digital Circuit Design Binary Arithmetic & Negative Numbers Fri, Aug 28 CEC 220 Digital Circuit Design Slide 1 of 14.
IT1004: Data Representation and Organization Negative number representation.
CHAPTER 6 ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS.
1 CS 151 : Digital Design Chapter 4: Arithmetic Functions and Circuits 4-3 : Binary Subtraction.
Chapter 4 Operations on Bits. Apply arithmetic operations on bits when the integer is represented in two’s complement. Apply logical operations on bits.
Microprocessor & Assembly Language
{ Binary “There are 10 types of people in the world: Those who understand binary, and those who don't.”
1 Integer Representations V1.0 (22/10/2005). 2 Integer Representations  Unsigned integer  Signed integer  Sign and magnitude  Complements  One’s.
COSC2410: LAB 2 BINARY ARITHMETIC SIGNED NUMBERS FLOATING POINT REPRESENTATION BOOLEAN ALGEBRA 1.
Negative Number Sign-Magnitude: left-most bit as the sign bit –16 bits –Example: 4-bit numbers is given by is given by ’s complement:
David Kauchak CS 52 – Spring 2017
Chapter 4 Operations on Bits.
Boolean Algebra, Bitwise Operations
Fractions: Adding and Subtracting Like Denominators
Addition and Substraction
Fractions: Adding and Subtracting Like Denominators
Unit 18: Computational Thinking
Negatives, Addition, Subtraction
By: A. H. Abdul Hafez CAO, by Dr. A.H. Abdul Hafez, CE Dept. HKU
Estimating Sums and Differences of Fractions and Mixed Numbers
Estimating Sums and Differences
CPS120: Introduction to Computer Science
Instructor: Alexander Stoytchev
ECE 331 – Digital System Design
ARITHMETIC, LOGIC INSTRUCTIONS, AND PROGRAMS
Overview Fractions & Sign Extension Floating Point Representations
Chapter3 Fixed Point Representation
靜夜思 床前明月光, 疑是地上霜。 舉頭望明月, 低頭思故鄉。 ~ 李白 李商隱.
Bit Manipulations CS212.
Presentation transcript:

EECC201 Freshman Seminar Intro to Micro controller Dr. Ken Hsu WEEK 7 ADDITION, SUBTRACTION AND COMPARE OF BINARY NUMBERS Important: Irritant sounds may be heard during browsing. Better turn the volume off.

Binary numbersUnsigned decimalSigned DecimalHexadecimal A B C D E F

2’S COMPLEMENT 0100 Take 1’s complement 1011Add 1 to result Get 2’s complement

To distinguish between two numbers with the same sign and two numbers with different signs in assembly language programming ANDNum1,#80H ANDNum2,#80H XORNum1,Num2 If result of XOR = 0 then Z flag is set to 1 and sign of both numbers is the same If result of XOR = 1 then Z flag is set to 0 and sign of the numbers are different. NOTE: 80H is called a MASK.

ADDITION Unsigned number addition (1)Numbers with same sign (a)Positive c CY flag set to 1 This means that more than 4 bit is needed to represent sum. Carry 1 bit + 1 XOR 1 = No overflow

ADDITION Signed number addition (1)Numbers with same sign (a)Negative XOR 1 = No overflow CY flag set to 1 Ignore carry since there is no overflow

ADDITION Signed number addition (1)Numbers with different sign CY flag set to 0

SUBTRACTION (COMPARE CMP) Unsigned number subtraction (1)Numbers with different sign Do 2’s Complement with second number and add with first number Carry is 0. Make sign bit positive and thus equal to 8 and not XOR 1 = overflow

SUBTRACTION (COMPARE CMP) Unsigned number subtraction (1)Numbers with same sign (a)Positive Do 2’s Complement with second number and add with first number Ignore carry since there is no overflow 1 XOR 1 = No overflow

SUBTRACTION (COMPARE CMP) Unsigned number subtraction (1)Numbers with same sign (a)Negative Do 2’s Complement with second number and add with first number Ignore CY since there is no overflow 1 XOR 1 = No overflow

SUBTRACTION (COMPARE CMP) Unsigned number subtraction (1)Numbers with different sign Do 2’s Complement with second number and add with first number Overflow. This means that more than 4 bit is needed to represent number. 1 XOR 0 = overflow

AVERAGE OF 2 NUMBERS NOTE: If the average of a positive number gives a fraction, round fraction down Rotate right with carry by 1 bit. RORC (1) Average of a positive number with a whole result

Rotate right with carry by 1 bit. RORC (1) Average of a positive number with a fractional result. AVERAGE OF 2 NUMBERS NOTE: If the average of a positive number gives a fraction, round fraction down. 7

Rotate right with carry by 1 bit. RORC (1) Average of a negative number with a whole result. AVERAGE OF 2 NUMBERS NOTE: If the average of a negative number gives a fraction, round fraction down. 1111

Rotate Right with carry by 1 bit. RORC (1) Average of a negative number with a fractional result. AVERAGE OF 2 NUMBERS NOTE: If the average of a negative number gives a fraction, round fraction down NOT1 CY