1 / 120

Assembly Language and Computer Architecture Using C++ and Java

Assembly Language and Computer Architecture Using C++ and Java. 5/27/05. Chapter 1. Number Systems. Would you trust a medical doctor who did not know the location of the human appendix? Not likely. A doctor must know the structure and operation of the human body.

jalila
Download Presentation

Assembly Language and Computer Architecture Using C++ and Java

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. Assembly Language and Computer Architecture Using C++ and Java 5/27/05

  2. Chapter 1 Number Systems

  3. Would you trust a medical doctor who did not know the location of the human appendix?Not likely.A doctor must know the structure and operation of the human body.

  4. Similarly, a computer expert must know the structure and operation of computers. Providing a clear, concrete, and thorough view of the structure and operation of computers is our objective.

  5. Positional number systems • Decimal: base 10 • Binary: base 2 • Hexadecimal: base 16

  6. Decimal • Ten symbols: 0, 1, 2, …, 9 • Weights change by a factor of 10 from one position to the next. • Shifting the decimal point changes the value by a factor of 10 for each position shifted. • Each symbol is called a “digit”

  7. 25.4 decimal

  8. 25.4 decimal =

  9. Binary • Two symbols: 0 and 1 • Weights change by a factor of 2 from one position to the next. • Shifting the binary point changes the value by a factor of 2 for each position shifted. • Each symbol is called a “bit”.

  10. 1011.1 binary

  11. Most and least significant bits 0111010110010111 MSB LSB

  12. Hexadecimal • Sixteen symbols: 0, 1, 2, …, 9, A, B, C, D, E, F • Weights change by a factor of 16 from one position to the next. • Shifting the hexadecimal point changes the value by a factor of 16 for each position shifted. • Each symbol is called a “hex digit” • A = 10 decimal B = 11 decimal • C = 12 decimal D = 13 decimal • E = 14 decimal F= 15 decimal

  13. 1CB.8 hex

  14. Memorize this table 8 4 2 1

  15. Complement of a symbol s in a base n system (n – 1) - s Binary: Complement of 1 is 1 – 1 = 0 Decimal: Complement of 3 = 9 – 3 = 6 Hex: Complement of 4 = 15 – 4 = 11 = B

  16. Byte • Sequence of 8 bits • Each bit has two possibilities: 0 or 1 • Thus, there are 2x2x2x2x2x2x2x2 = 28 distinct patterns

  17. Example: 128 distinct numbers are representable with 7 bits but the number 128 requires 8 (7+1) bits to be represented

  18. Arithmetic with positional numbers Rules are essentially the same for all bases

  19. Arithmetic in decimal

  20. Adding in binary

  21. Subtraction in binary

  22. Addition in hex

  23. Subtraction in hex

  24. Converting to base n • Integer part: Repeatedly divide by n. Remainders are the digits of the base n number (in reverse order). • Fractional part: Repeatedly multiply by n. Whole parts are the digits of the base n number ( times n = move decimal point to the right one place).

  25. Each remainder is a digit

  26. Convert 11 decimal to binary 11 decimal = 1011 binary

  27. Convert 30 decimal to hex 30 decimal = 1E hex

  28. Division: Each whole part is a digit (strip whole part of product after each multiplication by 10) .43 x 10 1st digit 4. 3 x 10 2nd digit 3. 0

  29. Convert .6875 decimal to binary .6875 decimal = .1011 binary

  30. Repeating fraction .1 decimal = .0 0011 0011 ... binary

  31. Converting between binary and hex • Very easy to do • The ease of conversion is the reason why hex is often used as a shorthand representation of binary. • To do conversion, you need to know the binary-hex equivalents for the numbers 0 to 15.

  32. Binary to hex

  33. Hex to binary

  34. Horner’s method Efficient technique for converting to a new number base (just multiple by that base)

  35. Inefficient evaluation of 2CD5

  36. Use Horner’s rule to convert 2CD5

  37. Horner’s rule written horizontally

  38. Horner’s Rule Algorithm N = 0; Get keystroke; While (keystroke is digit) { N = N * 10 + keystroke; Get keystroke; }

  39. Convert 38 to binary using Horner’s rule Shift right == *2 corresponds to position of multiplier

  40. Signed binary numbers • Sign-Magnitude • Two’s Complement • One’s Complement • Excess-n

  41. Sign-magnitude Exercise: Add these two numbers???

  42. Adding sign-magnitude requires sign analysis: Like signs, then add magnitudes Unlike signs, then subtract magnitudes Sign-magnitude representation not good for computers

  43. Two’s complement The two’s complement of the number M is the number which yields 0 when added to M. Just the definition of negative

  44. Note this behavior what number is this? So 1111…1 is just 1 less than 0. Remember that.

  45. Simply “flipping” the bits does not yield the two’s complement. But you are not far from 0; just add 1

  46. Getting the two’s complement • Simply flipping the bits does not yield the two’s complement—it yields all 1’s. • But adding 1 to all 1’s yields all 0’s. • So flipping the bits and adding 1 should yield the two’s complement.

  47. Flip bits and add 1

  48. Two’s complement of 1

  49. 3-bit two’s complement numbers

  50. Terminology

More Related