Datorteknik IntegerAddSub bild 1 Integer arithmetic Depends what you mean by "integer" Assume at 3-bit string. –Then we define zero = 000 one = 001 Use.

Slides:



Advertisements
Similar presentations
TWO STEP EQUATIONS 1. SOLVE FOR X 2. DO THE ADDITION STEP FIRST
Advertisements

Advanced Piloting Cruise Plot.
Feichter_DPG-SYKL03_Bild-01. Feichter_DPG-SYKL03_Bild-02.
© 2008 Pearson Addison Wesley. All rights reserved Chapter Seven Costs.
Copyright © 2003 Pearson Education, Inc. Slide 1 Computer Systems Organization & Architecture Chapters 8-12 John D. Carpinelli.
Chapter 1 The Study of Body Function Image PowerPoint
Copyright © 2011, Elsevier Inc. All rights reserved. Chapter 6 Author: Julia Richards and R. Scott Hawley.
Author: Julia Richards and R. Scott Hawley
1 Copyright © 2013 Elsevier Inc. All rights reserved. Appendix 01.
Properties Use, share, or modify this drill on mathematic properties. There is too much material for a single class, so you’ll have to select for your.
UNITED NATIONS Shipment Details Report – January 2006.
What two numbers will give you a product of 64 and a quotient of 4?
1 RA I Sub-Regional Training Seminar on CLIMAT&CLIMAT TEMP Reporting Casablanca, Morocco, 20 – 22 December 2005 Status of observing programmes in RA I.
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Jeopardy Q 1 Q 6 Q 11 Q 16 Q 21 Q 2 Q 7 Q 12 Q 17 Q 22 Q 3 Q 8 Q 13
Title Subtitle.
Properties of Real Numbers CommutativeAssociativeDistributive Identity + × Inverse + ×
Exit a Customer Chapter 8. Exit a Customer 8-2 Objectives Perform exit summary process consisting of the following steps: Review service records Close.
DIVIDING INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
ADDING INTEGERS 1. POS. + POS. = POS. 2. NEG. + NEG. = NEG. 3. POS. + NEG. OR NEG. + POS. SUBTRACT TAKE SIGN OF BIGGER ABSOLUTE VALUE.
SUBTRACTING INTEGERS 1. CHANGE THE SUBTRACTION SIGN TO ADDITION
MULT. INTEGERS 1. IF THE SIGNS ARE THE SAME THE ANSWER IS POSITIVE 2. IF THE SIGNS ARE DIFFERENT THE ANSWER IS NEGATIVE.
FACTORING ax2 + bx + c Think “unfoil” Work down, Show all steps.
Year 6 mental test 5 second questions
Year 6 mental test 10 second questions
A Simple ALU Binary Logic.
Around the World AdditionSubtraction MultiplicationDivision AdditionSubtraction MultiplicationDivision.
2010 fotografiert von Jürgen Roßberg © Fr 1 Sa 2 So 3 Mo 4 Di 5 Mi 6 Do 7 Fr 8 Sa 9 So 10 Mo 11 Di 12 Mi 13 Do 14 Fr 15 Sa 16 So 17 Mo 18 Di 19.
REVIEW: Arthropod ID. 1. Name the subphylum. 2. Name the subphylum. 3. Name the order.
PP Test Review Sections 6-1 to 6-6
ABC Technology Project
EU market situation for eggs and poultry Management Committee 20 October 2011.
EU Market Situation for Eggs and Poultry Management Committee 21 June 2012.
2 |SharePoint Saturday New York City
Green Eggs and Ham.
VOORBLAD.
1 Breadth First Search s s Undiscovered Discovered Finished Queue: s Top of queue 2 1 Shortest path from s.
Factor P 16 8(8-5ab) 4(d² + 4) 3rs(2r – s) 15cd(1 + 2cd) 8(4a² + 3b²)
Basel-ICU-Journal Challenge18/20/ Basel-ICU-Journal Challenge8/20/2014.
1..
CONTROL VISION Set-up. Step 1 Step 2 Step 3 Step 5 Step 4.
© 2012 National Heart Foundation of Australia. Slide 2.
Understanding Generalist Practice, 5e, Kirst-Ashman/Hull
Model and Relationships 6 M 1 M M M M M M M M M M M M M M M M
25 seconds left…...
Subtraction: Adding UP
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
Januar MDMDFSSMDMDFSSS
Week 1.
Analyzing Genes and Genomes
We will resume in: 25 Minutes.
©Brooks/Cole, 2001 Chapter 12 Derived Types-- Enumerated, Structure and Union.
Essential Cell Biology
Intracellular Compartments and Transport
PSSA Preparation.
Essential Cell Biology
Datorteknik TopologicalSort bild 1 To verify the structure Easy to hook together combinationals and flip-flops Harder to make it do what you want.
1 Chapter 13 Nuclear Magnetic Resonance Spectroscopy.
Energy Generation in Mitochondria and Chlorplasts
CpSc 3220 Designing a Database
Datorteknik DataHazard bild 1 Data Hazards 0x30 sub $6 $0 $1 0x34 add $7 $6 $
Computer Engineering page 1 Integer arithmetic Depends what you mean by “integer”. Assume at 3-bit string. –Then we define: zero = 000 one = 001 Use zero,
Integer arithmetic Depends what you mean by "integer"
Presentation transcript:

Datorteknik IntegerAddSub bild 1 Integer arithmetic Depends what you mean by "integer" Assume at 3-bit string. –Then we define zero = 000 one = 001 Use zero, one and binary addition: Zero 000 One Zero + one = one. Makes sense!

Datorteknik IntegerAddSub bild 2 Add one repeatedly, use up all possible patterns: Zero Called the Unsigned Integer System No negative integers!

Datorteknik IntegerAddSub bild 3 Two additions:

Datorteknik IntegerAddSub bild 4 Two additions: Yes! 5 =  001; 001 represents one. is = 1???

Datorteknik IntegerAddSub bild 5 Addition of unsigned integers Error detected by presence of "carry"

Datorteknik IntegerAddSub bild 6 How do we subtract unsigned integers? We need the concept of the "Two's complement"

Datorteknik IntegerAddSub bild 7 One's complement Take any string Invert every bit 0 1 This is One's complement "NOT"

Datorteknik IntegerAddSub bild 8 Two's complement Given a string One's complement then add one This is called two's complement

Datorteknik IntegerAddSub bild 9 To subtract unsigned A-B Perform A + 2's comp (B) = A + Not (B) + 1

Datorteknik IntegerAddSub bild 10 Example: Carry! =2; Good! No Carry! =6; BAD!

Datorteknik IntegerAddSub bild 11 Subraction of unsigned integers Error detected by absence of carry! –Warning: Some machines invert the carry bit on subtraction –So that "carry" => Error for both add and sub

Datorteknik IntegerAddSub bild 12 Conclusion For unsigned arithmetic we are interested in carry Pay attention! I never used the word "overflow" thats something completely different. Also notice: –3-bit operands gave 3-bit results. –Don't be tempted to write that 4'th bit down!

Datorteknik IntegerAddSub bild 13 How about negative numbers? How should we represent -1 ? How would we compute 0 - 1? 0 + 2's compl (1) We choose this as our "-1" 1 = =

Datorteknik IntegerAddSub bild 14 Repeatedly add -1: Zero Less than zero No! High order bit called "sign bit"

Datorteknik IntegerAddSub bild 15 Signed 3-bit integers Not symmetrical around zero!!!

Datorteknik IntegerAddSub bild 16 Sign bit The high order bit in a number Also called "N"-bit Value is negative when this bit is "1"

Datorteknik IntegerAddSub bild 17 Let's try A + B (-1) *000 Both results is OK But: Left case: no carry Right case: carry Conclusion: For signed addition carry is worthless Same conclusion for signed subtraction * carry

Datorteknik IntegerAddSub bild 18 Some additions A (-3) (-4) (-2)

Datorteknik IntegerAddSub bild 19 Some additions B (-3) (-4) C C (-2)

Datorteknik IntegerAddSub bild 20 Some additions C OK BAD (-3) (-4) C C OK BAD (-2) OK OK

Datorteknik IntegerAddSub bild 21 Some additions D OK BAD (-3) (-4) C C OK BAD (-2) OK OK

Datorteknik IntegerAddSub bild 22 Error during signed addition: R = A + B A, B same sign and R opposite sign called overflow Notice: Matematically, signed addition is the same as unsigned addition The same is true for signed subtraction and unsigned subtraction A - B –> A + (-B) –> A + 2's compl (B)

Datorteknik IntegerAddSub bild 23 Some subtractions A (-1) (-1)

Datorteknik IntegerAddSub bild 24 Some subtractions B (-1) C (-1) C C C 0 1 1

Datorteknik IntegerAddSub bild 25 Some subtractions C (-1) C OK BAD (-1) C OK OK C C OK BAD

Datorteknik IntegerAddSub bild 26 Some subtractions D (-1) C OK BAD (-1) C OK OK C C OK BAD

Datorteknik IntegerAddSub bild 27 Error during signed subtraction: R = A - B A, B different sign and B, R same sign called overflow

Datorteknik IntegerAddSub bild 28 Arithmetic- logic unit (ALU) C = carry V = overflow N = sign bit of R Z = 1 if R = 0 32 A B C Operation Condition codes C, V, N, Z

Datorteknik IntegerAddSub bild 29 Compare two unsigned numbers? is A < B ? Easy! Compute A - B and examine carry But – to compare two signed numbers? is A < B ? Most common mistake: –Compute R = A - B, then look at sign of R. –If R < 0 then A < B (N-bit) Not good enough!

Datorteknik IntegerAddSub bild 30 To compare two signed numbers: What about A = - 4 B = 3 (- 4) c 001 Assumption: “If R neg then A < B” We conclude A  B, that is - 4  3 Wrong!

Datorteknik IntegerAddSub bild 31 Some examples A (-1) (-1)

Datorteknik IntegerAddSub bild 32 Some examples B (-1) C < +1? No! 3 < -1? No! (-1) C < -1? No! 1 < -1? No! C C < +1? Yes! -4 < 1? Yes!

Datorteknik IntegerAddSub bild 33 Some examples C (-1) C < +1? No! 3 < -1? No! N = 0, V = 0 N = 1, V = (-1) C < -1? No! 1 < -1? No! N = 0, V = 0 N = 0, V = C C < +1? Yes! -4 < 1? Yes! N = 1, V = 0 N = 0, V = 1

Datorteknik IntegerAddSub bild 34 To compare signed numbers: Compute R = A - B A < B true if N and V are different A<B = exor(N,V) after computation