Assembly Language for Intel-Based Computers Chapter 5: Procedures Kip R. Irvine.
ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS DATA REPRESENTATION PART 1.
-
Upload
piers-brown -
Category
Documents
-
view
227 -
download
2
Transcript of ASSEMBLY LANGUAGE FOR INTEL-BASED COMPUTERS DATA REPRESENTATION PART 1.
Web site Examples
DATA FORMATS
Computers
• Process and store all forms of data in binary format
Human communication
• Includes language, images and sounds
Data formats:
• Specifications for converting data into computer-usable form
• Define the different ways human data may be represented, stored and processed by a computer
2
Web site Examples
SOURCES OF DATABinary input
◦ Begins as discrete input ◦ Example: keyboard input such as A 1+2=3 math◦ Keyboard generates a binary number code for each key
Analog◦ Continuous data such as sound or images◦ Requires hardware to convert data into binary numbers
3
Computer
1101000101010101…
Input device
A 1+2=3 math
Figure 3.1 with this color scheme
Web site Examples
COMMON DATA REPRESENTATIONS
Type of Data Standard(s)
Alphanumeric Unicode, ASCII, EDCDIC
Image (bitmapped) GIF (graphical image format)TIF (tagged image file format)PNG (portable network graphics)
Image (object) PostScript, JPEG, SWF (Macromedia Flash), SVG
Outline graphics and fonts
PostScript, TrueType
Sound WAV, AVI, MP3, MIDI, WMA
Page description PDF (Adobe Portable Document Format), HTML, XML
Video Quicktime, MPEG-2, RealVideo, WMV 4
Web site Examples
INTERNAL COMPUTER DATA FORMAT
All data stored as binary numbers
Interpreted based on
• Operations computer can perform• Data types supported by programming language
used to create application
5
Web site Examples
INTERNAL DATA REPRESENTATIONReflects the
◦ Complexity of input source◦ Type of processing required
Trade-offs◦ Accuracy and resolution
Simple photo vs. painting in an art book◦ Compactness (storage and transmission)
More data required for improved accuracy and resolution Compression represents data in a more compact form Metadata: data that describes or interprets the meaning of data
◦ Ease of manipulation: Processing simple audio vs. high-fidelity sound
◦ Standardization Proprietary formats for storing and processing data (WordPerfect vs.
Word) De facto standards: proprietary standards based on general user
acceptance (PostScript)
6
Web site Examples
5 SIMPLE DATA TYPES
Boolean: 2-valued variables or constants with values of true or false
Char: Variable or constant that holds alphanumeric character
Enumerated◦User-defined data types with possible values listed
in definition Type DayOfWeek = Mon, Tues, Wed, Thurs, Fri, Sat, Sun
Integer: positive or negative whole numbers Real
◦Numbers with a decimal point◦Numbers whose magnitude, large or small, exceeds
computer’s capability to store as an integer
7
Web site Examples
DATA TYPES: NUMERIC
Used for mathematical manipulation◦ Add, subtract, multiply, divide
Types◦ Integer (whole number)◦ Real (contains a decimal point)
pure binary◦ can be calculated directly
ASCII binary◦ string of digits: "01010101"
ASCII decimal◦ string of digits: "65"
ASCII hexadecimal◦ string of digits: "9C"
8
Web site Examples
DATA TYPES: ALPHANUMERIC
Alphanumeric: • Characters: b T• Number digits: 7 9• Punctuation marks: ! ; • Special-purpose characters: $ &
Numeric characters vs. numbers• Both entered as ordinary characters• Computer converts into numbers for calculation
• Examples: Variables declared as numbers by the programmer (Salary$ in BASIC)
• Treated as characters if processed as text• Examples: Phone numbers, ZIP codes
9
Web site Examples
ALPHANUMERIC CODES
Arbitrary choice of bits to represent characters
• Consistency: input and output device must recognize same code
• Value of binary number representing character corresponds to placement in the alphabet
• Facilitates sorting and searching
10
Web site Examples
DATA REPRESENTATION
Binary Numbers◦ Translating between binary and decimal
Binary AdditionInteger Storage SizesHexadecimal Integers
◦ Translating between decimal and hexadecimal◦ Hexadecimal subtraction
Signed Integers◦ Binary subtraction
Character Storage
11
Web site Examples
BINARY, OCTAL, DECIMAL AND HEXADECIMAL DIGITS TABLE
12
System Base Possible Digits
Binary 2 0 1
Octal 8 0 1 2 3 4 5 6 7
Decimal 10 0 1 2 3 4 5 6 7 8 9
Hexadecimal
16 0 1 2 3 4 5 6 7 8 9 A B C D E F
Web site Examples
BINARY NUMBERS
Digits are 1 and 0
• 1 = true• 0 = false
MSB – most significant bit
LSB – least significant bit
Bit numbering:
13
015
1 0 1 1 0 0 1 0 1 0 0 1 1 1 0 0
MSB LSB
Web site Examples
BINARY NUMBERS
Binary integers can be signed or unsigned.
Signed integer = either positive or negative
Unsigned integer = only positive, including 0.
14
Web site Examples
UNSIGNED BINARY INTEGERS
Each digit (bit) is either 1 or 0
Each bit represents a power of 2
15
Every binary number is a sum of powers of 2
Web site Examples
TRANSLATING UNSIGNED BINARY TO DECIMALWeighted positional notation shows how to calculate the decimal value of each binary bit:
dec = (Dn-1 2n-1) (Dn-2 2n-2) ... (D1 21) (D0 20)D = binary digit
binary 00001001 = decimal 9:
How to calculate?
( 0 27)+(0 26)+(0 25)+(0 24)+(1 23)+(0 22)+ (0 21)+ (1 20)
0 + 0 + 0 + 0 + 8 + 0 + 0 + 1
9
16
Web site Examples
TRANSLATING UNSIGNED DECIMAL TO BINARYRepeatedly divide the decimal integer by 2. Each remainder is a
binary digit in the translated value:
18
37 = 1001012
Web site Examples
BINARY ADDITION
Starting with the LSB, add each pair of digits, include the carry if present.
20
Web site Examples
INTEGER STORAGE SIZES
21
What is the largest unsigned integer that may be stored in 20 bits?
Standard sizes:
Web site Examples
TRANSLATING BINARY TO HEXADECIMAL
23
• Each hexadecimal digit corresponds to 4 binary bits.
• Example: Translate the binary integer 000101101010011110010100 to hexadecimal:
Web site Examples
POWERS OF 16FROM 160 TO 167
24
Used when calculating hexadecimal values up to 8 digits long:
Web site Examples
CONVERTING HEXADECIMAL TO DECIMAL
Multiply each digit by its corresponding power of 16:
decimal = (D3 163) + (D2 162) + (D1 161) + (D0 160)
Hex 1234 equals (1 163) + (2 162) + (3 161) + (4 160), or decimal 4,660.
Hex 3BA4 equals (3 163) + (11 * 162) + (10 161) + (4 160), or decimal 15,268.
25
Web site Examples
CONVERTING HEXADECIMAL TO DECIMAL (CONT)
Hex 3BA4 equals
3 163 = 12 288
+ 11 * 162 = 2 816
+ 10 161 = 160
+ 4 160 = 4
15,268
26
Try this:
1. 1C592. ABCD
Web site Examples
CONVERTING DECIMAL TO HEXADECIMAL
27
decimal 422 = 1A6 hexadecimal
Try this:
1. 1002. 2108
Web site Examples
HEXADECIMAL ADDITION
Divide the sum of two digits by the number base (16). The quotient becomes the carry value, and the remainder is the sum digit.
28
Try This 36 28 28 +42 + 45 + B8
21/16 = 1, remain 5
1/16 = 0, remain 1
Important skill: Programmers frequently add and subtract the addresses of variables and instructions.
eg: 1
6 A 6 | 10+ 4 B 4 | 11
11 | 21 B 5
Web site Examples
SOLUTION A1 :
36
+ 42
78
29
A2 :
2 | 8
+ 4 | 5
6 | 13 6 D
13 = D
A3 : 1
2 | 8
+ B | 8
14 | 16 E 0
16 /16 = 1 remain 0
1/16 = 0 remain 114 = E
Web site Examples
HEXADECIMAL SUBTRACTIONWHEN A BORROW IS REQUIRED FROM THE DIGIT TO THE LEFT, ADD 16 (DECIMAL) TO THE CURRENT DIGIT'S VALUE:
C 6 12 6
- A 2 -10 2
2 4
30
16
2 8 16
3 9 5 3 9 5
- D A - 13 10
2 11 11
2 B B (16+5)-10 =11
(16+8)-13 =11
Web site Examples
HEXADECIMAL SUBTRACTION
31
1) 16 + 5 = 21
2) 21 – 7 = 14
3) 14 = E
6 16
7 5- 4 7 2 E
E F- B 2 3 D
1) F = 152) 15 – 2 = 133) 13 = D4) E =145) B = 116) 14 – 11 = 3
Web site Examples
TRY THIS
Hexadecimal addition
1. D3A + 19
2. 99+ A11
3. 6B2 + FF
32
Hexadecimal subtraction
1. D1A - 339
2. A11 - 99
3. 74B – 8F
Web site Examples
SIGNED INTEGERS
The highest bit indicates the sign. 1 = negative, 0 = positive
33
If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples: 8A, C5, A2, 9D
Web site Examples
SIGNED-INTEGER REPRESENTATION
No obvious direct way to represent the sign in binary notation
Options:
• Sign-and-magnitude representation• 1’s complement• 2’s complement (most common)
34
Web site Examples
SIGN-AND-MAGNITUDE
Use left-most bit for sign
• 0 = plus; 1 = minus
Total range of integers the same
• Half of integers positive; half negative• Magnitude of largest integer half as large
Example using 8 bits:
• Unsigned: 1111 1111 = +255• Signed: 0111 1111 = +127
1111 1111 = -127• Note: 2 values for 0:
+0 (0000 0000) and -0 (1000 0000)
35
Web site Examples
1’S VS. 2’S COMPLEMENTS
Choice made by computer designer
1’s complement
• Reverse the bit• Easier to change sign• Addition requires extra end-around carry• Algorithm must test for and convert -0
2’s complement simpler
• Additional add operation required for sign change
36
Web site Examples
FORMING THE TWO'S COMPLEMENT
Negative numbers are stored in two's complement notation
Represents the additive Inverse
37
Note that 00000001 + 11111111 = 00000000
Web site Examples
FORMING TWO’S COMPLEMENT OF HEXADECIMAL
6A3D
1. Step 1: reverse the bits = 95C2
2. Step 2: Add 1 = 95C3
38
Web site Examples
LEARN HOW TO DO THE FOLLOWING:
Form the two's complement of a hexadecimal integer
Convert signed binary to decimal
Convert signed decimal to binary
Convert signed decimal to hexadecimal
Convert signed hexadecimal to decimal
39
Web site Examples
GUIDELINES
Convert signed binary to decimal1. If number is negative, form two complement notation2. Convert to decimal
Convert signed decimal to binary1. Convert to binary 2. If number is negative, form two complement notation
Convert signed decimal to hexadecimal1. Convert to hexadecimal2. If number is negative, form two complement notation
Convert signed hexadecimal to decimal1. If number is negative, form two complement notation2. Convert to decimal
40
Web site Examples
**NOTES**
Any hexadecimal number
• If digit is >= 8, the number is negative• If digit is <=7, the number is positive
Eg :
• 8A20 = negative• 7FD9 = positive
41
Web site Examples
RANGES OF SIGNED INTEGERS
42
The highest bit is reserved for the sign. This limits the range:
Practice: What is the largest positive value that may be stored in 20 bits?
Web site Examples
NUMERIC DATA REPRESENTATION
pure binary
• can be calculated directly
ASCII binary
• string of digits: "01010101"
ASCII decimal
• string of digits: "65"
ASCII hexadecimal
• string of digits: "9C"
43
next: Boolean Operations
Web site Examples
LEARN HOW TO DO THE FOLLOWING:
Form the two's complement of a hexadecimal integer
• 3D C2 (First complement)
+ 1
C3 (Two’s Complement)
Convert signed binary to decimal
• 1111 0000 0000 1111 (First complement) + 1 0001 0000 (Two’s Complement) 0001 0000 =( 1 X 2 ^ 5) =16 =16
44
Web site Examples
LEARN HOW TO DO THE FOLLOWING:Convert signed decimal to binary
• - 43 =?
43= 00101011 Two’s Complement: 0010 1011 1101 0100 + 1 1101 0101
45
•Convert signed decimal to hexadecimal -18 =?* Twist
18=12 hexadecimal
Two’s complement: 15 15 - 1 2 E D + 1 E E