Assembly Language I The Number Systems The Decimal
Assembly Language I The Number Systems
The Decimal Numbers u Base 10 u Has 10 single digits u Place values of a decimal number: 100, 101, 102, 103. . . u 79410 = 7*102 + 9*101 + 4*100
Binary Numbers u Base 2 u Has only 2 single digits: 0, 1 u Place values of a binary number: 20, 21, 22, 23, 24… u 101112 = 1*24 + 0*23 + 1*22 + 1*21 + 1*20 u Proposed by John Von Newmann that computers should be a Binary machine. Instructions as well as data should be stored as Binary numbers.
Octal Numbers u Base 8 u Has 8 single digits: 0, 1, 2, 3, 4, 5, 6, 7 u Place values of an octal number: 80, 81, 82, 83, 84… u 723058 = 7*84 + 2*83 + 3*82 + 0*81 + 5*80 u Octal numbers are shorthand for Binary numbers. Each Octal digit is euqal to 3 Binary digits.
Hexadecimal Numbers u Base 16 u Has 16 single digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F u Place values of a hexadecimal number: 160, 161, 162, 163, 164… u 6 AC 16 = 6*162 + 10*161 + 12*160 u Hex numbers are shorthand for Binary numbers. Each Hex digit is euqal to 4 Binary digits.
Conversions. Binary to Octal or Hex u Since Octal numbers and Hexadecimal numbers are just shorthand notation of Binary numbers, just group 3 Binary digits to make an Octal digit, and 4 Binary digits to make a Hexadecimal digit. u Always group the Binary digits from the right. Add leading 0 s if needed. u ex: 101101112 = 2678 = B 716
Conversions. Oct or Hex to Binary u Expand each Octal digit into 3 Binary digits u Expand each Hexadecimal digit into 4 Binary digits u ex: 37058 = 011 111 000 1012 u ex: 69 B 416 = 0110 1001 1011 01002
Conversions Decimal to Binary u Repeat dividing the Decimal number by 2 until 0, then record the remainders. u The binary equivalent is the remainders read from bottom up. u 7610 = 10011002 38 RMN 0 0 19 1 0 76 2 2 2 4 2 2 2 1 0 0 1
Conversion from Decimal to. . . Octal u Repeat dividing the decimal number by 8 until 0, then record the remainders. u The octal equivalent is the remainders read from bottom up. u 7610 = 1148 Hexadecimal u Repeat dividing the decimal number by 16 until 0, then record the remainders. u The hexadecimal equivalent is the remainders read from bottom up. u 7610 = 4 C 16
Conversions Binary, Octal, Hexadecimal to Decimal Associate each digit with its appropriate place value, then sum them up. u 101112 = 1*24 + 0*23 + 1*22 + 1*21 + 1*20 = 2310 u 723058 = 7*84 + 2*83 + 3*82 + 0*81 + 5*80 = 2989310 u 6 AC 16 = 6*162 + 10*161 + 12*160 = 170810
Integer Representation u How integers are represented inside of a computer. u Intel 80 X 86/88 Architecture Sizes: Byte (8 -bit), Word (16 -bit), Doubleword (32 -bit) u Signed Integers vs Unsigned Integers
Signed Integers 2’s Complement Scheme u Assuming dec eq there is a size of 4 -bit integers: 2’s comp dec eq 2’s comp 0 0000 -1 1111 1 2 3 4 5 6 7 0001 0010 0011 0100 0101 0110 0111 -2 -3 -4 -5 -6 -7 -8 1110 1101 1100 1011 1010 1001 1000
2’s Complement Integers u Determine the size of the integer first. u +5 + -5 = 0 (decimal) u 0101 + 1011 = 0000 (4 -bit 2’s complement) Original # 0101 1’s comp 1010 + 1 ___________ 2’s comp 1011
Convert decimal to 2’s Comp u Determine size of integer to be converted: 8 -bit, 16 -bit, or 32 -bit? u If the decimal number is positive, repeat dividing the decimal number by 2, then record the remainders (as shown before). Add leading 0’s to make up the size. u If the decimal number is negative, repeat dividing the absolute value of the number by 2 as above. Take the 2’s complement. The result is the negative of that absolute value number.
Example: How is -7610 represented as a word? u Determine size: word is 16 -bit u Use repeat division to find out 7610 = 0000 0100 11002 -7610 = 1111 1011 00112 (1’s comp) + 12 ___________________ 1111 1011 01002 (2’s comp)
2’s Complement Integers (Signed Integers) Size 8 -bit 16 -bit 32 -bit Largest +127 +32767 +2147483647 Smallest -128 -32768 -2147483648
Unsigned Integers Size 8 -bit Largest 255 (28 - 1) Smallest 0 16 -bit 85535 (216 - 1) 32 -bit 4294967295 (232 - 1) 0 0
Binary, Octal, Hexadecimal Arithmetic Same as decimal except carry or borrow is based on the base instead of 10. 11 111 CARRIES ex: 1001 01112 + 1100 10112 ________ 10110 00102 DROPPED INTO THE BIT BUCKET
Example: Subtract 37 C 5 600 D 16 2 D 58 094 A 16 _________ 0 A 6 D 56 C 316
Overflow u When adding or subtracting integers, the result becomes too large or too small to fit properly into the alloted size. If this occurs, it is an integer overflow. u Overflow may occur when adding two integers of the same sign, or subtracting an integer from another with a different sign. u ex: 1000 00002 - 0000 00012 0111 11112 + 0000 00012
- Slides: 20