Transcript ECE 291

ECE 291
Lecture 2:
Number Systems & x86 Instructions
Constantine D. Polychronopoulos
Professor, ECE
Office: 463 CSRL
Spring 2000
CDP
ECE 291 -- Spring 2000
Number Systems - Review ECE 290!!
• Decimal numbers (or base 10 system) - Notation: 0,1,…9:
– Example: 378 = 3 * 102 + 7 * 101 + 8 * 100
• Binary numbers (or base 2 system) - Notation: 0 and 1:
– Example: (001101)2 = 1 * 23 + 1 * 22 + 0 * 21 + 1 * 20 = 8+4+1=(13)10
• Hexadecimal numbers (or base 16 system) - Notation:
0..9,A,B,C,D,E,F:
– Example: 52A4F = 5*164 + 2*163 + 10*162 + 4*161 + 15*160
• Many other representations
– BCD (Binary Coded Decimal): decimal numbers represented in binary notation
with each decimal digit represented by its 4-bit binary encoding:
• Example: 728 in BCD is 0111 0010 1000
CDP
ECE 291 -- Spring 2000
Base Conversion
• Always easy to convert from any base b to decimal: just compute the
sum of products - result is in decimal.
• Converting from decimal to base b: Successive division or (remainder)
decimal with the largest power of b - successive quotients form base b
representation.
– Example: Convert 77 to binary representation.
•
•
•
•
Divide 77 by 64 (26) - Q = 1
Divide 13 by 8 (23) - Q = 1
Divide 5 by 4 (22) - Q = 1
Divide 1 by 1 (20) - Q = 1
R=13
R=5
R=1
R=0 --- DONE
– Result: 77 = 1 0 0 1 1 0 1
– Put 1’s where Q=1 and 0’s in the remaining positions
CDP
ECE 291 -- Spring 2000
Converting Fractional Part
• 1- Multiply fraction with base
• 2- Save integer digit (if any)
• 3- Repeat until remainder=0 or accuracy is obtained
• 4- The successive digits form the converted fractional
representation
– Example: Converting .173 to octal representation
• .173 X 8 =
• .384 X 8 =
• .072 X 8 =
1.384 Save 1
3.072 Save 3
0.576 Save 0
– .173 in base 10 = .130… octal
CDP
ECE 291 -- Spring 2000
Radix-1 & Radix Complement Representation
• One’s complement representation:
– Subtract n-bit binary representation from n-bit all 1’s (radix-1)
• Two’s complement representation:
– As in One’s complement + add 1 to the result (radix)
• One of the problem with (radix-1) complement representation is
inability to uniquely represent zero.
• Two’s complement gives you the inverted (negated) number: if
you add a number and its (radix) complement discarding any
overflow, the result is ZERO!
CDP
ECE 291 -- Spring 2000
Signed & Unsigned Representations
• First bit in binary rep. is sign bit:
– s=0: positive (+)
– s=1: negative (-)
• Two quick schemes to represent a negative number N (any of
them will work):
– Invert all bits then add 1 (2’s complement)
– Scan N from right to left: copy 0’s, copy first 1, invert the rest
• Sign-extending a number: copy sign bit into extra leftmost
positions
CDP
ECE 291 -- Spring 2000
Memory Objects & Data Types
• Data Types
•
CDP
Numbers
•
bit (eg: 1)
•
nibble = 4 bits
•
DB:byte = octet = 8 bits
•
DW:Word = 2 bytes = 16 bits (80x86 terminology)
•
DD:DoubleWord = 4 bytes = 32 bits (80x86 terminology)
•
Intel uses little endian format (i.e., LSB at lower address)
•
Signed Integers (2's complement)
ECE 291 -- Spring 2000
Memory Objects (Cont.)
•
Text
•
Letters and characters (7-bit ASCII standard)
•
'A'=65=0x41
•
Extended ASCII (8-bit) allows for extra 128 graphics/symbols)
•
Collection of characters = Strings
•
Collection of Strings = Documents
•
Programs
•
Commands (MOV, JMP, AND, OR, NOT)
•
Collections of commands = procedures/functions/subroutines
•
Collection of subroutines = programs
•
CDP
ECE 291 -- Spring 2000
Memory Objects (Cont.)
CDP
•
Floating point numbers (covered later)
•
Images (GIF, TIF, JPG, BMP)
•
Video (MPEG, QuickTime, AVI)
•
Audio (voice, music)
ECE 291 -- Spring 2000