1 / 9

ADD/SUB revisited

ADD/SUB revisited. Understand the examples again Overflow When two positive numbers added together or a negative number subtracted from a positive number yields negative Underflow When two negative numbers added together or a positive number subtracted from a negative number yields positive

vern
Download Presentation

ADD/SUB revisited

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. ADD/SUB revisited • Understand the examples again • Overflow • When two positive numbers added together or a negative number subtracted from a positive number yields negative • Underflow • When two negative numbers added together or a positive number subtracted from a negative number yields positive C/B 0001 1111 0100 1000 1101 0000 1000 1100 A 0101 0101 0101 1001 0010 1011 0101 1011 B +0001 +1011 +0100 +1010 -0101 -1001 -1101 -0100 Res 0110 0000 1001 0011 1101 0010 1000 0111 Corr Corr Over Under Corr Corr Over Under

  2. Negation • To change sign of a number • In Sign and Magnitude • Just complement the sign • 1’s Complement • Complement all bits • 2’s Complement • Complement all bits and add 1 • Adding 1 is expensive operation (Example: Add 1 to 0111) • Alternate 2’s complement method • Scan the string from right • Retain all bits up to the first 1 • Then complement the remaining bits

  3. Converting negative number • Positive numbers are well understood • How to convert a negative decimal number to binary • Method 1: • The magnitude of number must be less than 2n-1 • Add -2n-1 to the number • Convert the magnitude of this number as an n-bit string • Example -4 + (-8) = -12 (decimal) = 1100 (binary) • Method 2 • Convert the magnitude to an n-bit string • Negate the number

  4. So what about logic functions • So far we discussed arithmetic (yes, no multiply/divide) • But what about a logic functions? • A binary variable can be used to represent two logic value • Answer to any question with two possible answers can be represented by a binary variable • Examples: • Does the second section of 210 meet at 10AM? Answer represented by variable A, value A=1 (yes), value A=0 (no) • Is it worth attending class at that time? Answer represented by variable B, value B=1 (yes), value B=0 (no)

  5. Functions of 1-bit variable • We can combine variables to get more complex functions • Functions of 1 variable X F1(X) F2(X) F3(X) F4(X) 0 0 1 0 1 1 0 1 1 0 • We have four possible operations upon 1 1-bit input value • F1 is always 0, F2 is always 1, F3 is always X and F4 is always complement of X • F4 is an important function and is called inversion • It is also called NOT operation • Inverse is denoted by X’ or X

  6. Functions of 2-bit variable X Y F0 F1 F2 F3 F4 F5 F6 F7 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1 X Y F8 F9 F10 F11 F12 F13 F14 F15 0 0 1 1 1 1 1 1 1 1 0 1 0 0 0 0 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 1 0 1 0 1 0 1 0 1

  7. Interpretation of function • F1 is called a logical AND denoted by X.Y • F6 is called an XOR denoted by X xor Y • F7 is called OR denoted by X + Y • F8 is NOR denoted by X + Y • F14 is NAND denoted by X.Y • Logic expressions allow us to implement function of binary inputs • For each logic expression there is a logic gate • See and practice logic circuit symbols for AND, OR, NAND, NOR, XOR, NOT…

  8. Combining logic circuits • Basic logic circuits can be combined to get a bigger function • Functions are written in truth table • Each row in a truth table is one combination of logic variable • Given the number of variables, n, we have 2n different entries • For example, for 1 variable there will 2 entries, for 4 variables there will be 16 entries, and so on • Most circuits may have many more than 4 inputs • However in class we will deal with only a few inputs • For example a function of four variables could be • F = (A+B).(C+D)

  9. An Example of Truth Table

More Related