Download presentation

Presentation is loading. Please wait.

Published byMilo Maher Modified about 1 year ago

1

2
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.

3
Binary numbersUnsigned decimalSigned DecimalHexadecimal A B C D E F

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

5
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.

6
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

7
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

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

9
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

10
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

11
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

12
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

13
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

14
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

15
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

16
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

Similar presentations

© 2017 SlidePlayer.com Inc.

All rights reserved.

Ads by Google