doc

advertisement
© Wendy Zhang, Computer Science & IT Department
Chapter 1: Basic Concepts
I. Objectives
•
•
•
•
•
•
•
•
•
•
•
Understand common applications of assembly language
Understand what an assembler does
Understand hardware and software requirements for the book
Know the basic history of PC Assemblers
Differentiate between protected mode and real-address mode
Learn basic principles of computer architecture as applied to the Intel IA-32 processor
family
Learn how to recognize and convert Boolean and hexadecimal integers
Perform binary addition and subtraction
Understand basic Boolean operations
Differentiate between signed and unsigned binary integers
Understand ASCII character representation
II. Lecture Notes
1. Welcome to Assembly Language
• What is Assembly Language?
o Oldest programming language
o Has a one-to-one relationship with machine language
o Provides direct access to computer hardware
• Some Good Questions to Ask
o Why am I learning Assembly Language? Helps you learn how software is constructed
at the lowest levels
o What background should I have? Complete a computer programming language
o What is an assembler? An utility program that converts source code program from
assembly language into machine language
o What hardware/software do I need? Intel386 or compatible processor and Microsoft
Macro Assembler 8.0 (MASM)
o What types of programs will I create? Intel-based x86 assembly language programs
o What do I get with this book?
o What will I learn?
o How does assembly language (AL) relate to machine language?
o How do C++ and Java relate to AL?
o Is AL portable? No.
o Why learn AL? Helps you to gain on overall understanding of the interaction
between computer hardware, operational systems, and applications
 Assembly Language Applications
o Business application for single platform
o Hardware device driver
o Business application for multiple platforms
o Embedded systems & computer games
o Real-time applications such as simulations and hardware monitoring
CMPS293
1
Chapter 1
© Wendy Zhang, Computer Science & IT Department

Comparing Assembly Language to High-Level Languages
2. Virtual Machine Concept
• Programming Language analogy:
o Each computer has a native machine language (language L0) that runs directly on its
hardware
o A more human-friendly language is usually constructed above machine language,
called Language L1
o Programs written in L1 can run two different ways:
 Interpretation – L0 program interprets and executes L1 instructions one by one
 Translation – L1 program is completely translated into an L0 program, which
then runs on the computer hardware
 Specific Machine Levels
o High-Level Language - Level 5
 Application-oriented languages
 C++, Java, Pascal, Visual Basic . . .
 Programs compile into assembly language (Level 4)
o Assembly Language - Level 4
 Instruction mnemonics that have a one-to-one correspondence to machine
language
 Calls functions written at the operating system level (Level 3)
 Programs are translated into machine language (Level 2)
CMPS293
2
Chapter 1
© Wendy Zhang, Computer Science & IT Department
o Operating System - Level 3
 Provides services to Level 4 programs
 Translated and run at the instruction set architecture level (Level 2)
o Instruction Set Architecture - Level 2
 Also known as conventional machine language
 Executed by Level 1 (microarchitecture) program
o Microarchitecture - Level 1
 Interprets conventional machine instructions (Level 2)
 Executed by digital hardware (Level 0)
o Digital Logic - Level 0
 CPU, constructed from digital logic gates
 System bus
 Memory
 Implemented using bipolar transistors
3. Data Representation
 Binary Numbers
o Digits are 1 and 0
1 = true
0 = false
o MSB – most significant bit
o LSB – least significant bit
o Bit numbering:
MSB
LSB
1011001010011100
15
0
Each binary digit (bit) is either 1 or 0
Each bit represents a power of 2:
1
1
1
1
1
1
1
1
27
26
25
24
23
22
21
20
o Every binary number is a sum of powers of 2
CMPS293
3
Chapter 1
© Wendy Zhang, Computer Science & IT Department



Translating Binary to Decimal
Weighted positional notation shows how to calculate the decimal value of each binary
bit:
dec = (Dn-1  n-1
Dn-2  2n-2
D1  21
D0  20)
D = binary digit
binary 00001001(2) = decimal 9(10)
(1  23) + (1  20) = 9
Translating Unsigned Decimal to Binary
Repeatedly divide the decimal integer by 2. Each remainder is a binary digit in the
translated value:
Binary Addition
Starting with the LSB, add each pair of digits, include the carry if present
carry:
+
bit position:

1
0
0
0
0
0
1
0
0
(4)
0
0
0
0
0
1
1
1
(7)
0
0
0
0
1
0
1
1
(11)
7
6
5
4
3
2
1
0
Integer Storage Sizes
Standard sizes:
byte
word
doubleword
8
16
32
quadword
CMPS293
64
4
Chapter 1
© Wendy Zhang, Computer Science & IT Department

Hexadecimal Integers

Translating Binary to Hexadecimal
o
Each hexadecimal digit corresponds to 4 binary bits.
o
i.e., Translate the binary integer 000101101010011110010100 to hexadecimal:


Binary 000101101010011110010100(2) equals hex 16A794(16)
Converting Hexadecimal to Decimal
o Multiply each digit by its corresponding power of 16:
dec = (D3  163) + (D2  162) + (D1  161) + (D0  160)
o Hex 1234(16) equals (1  163) + (2  162) + (3  161) + (4  160), or 4,660(10)
o Hex 3BA4(16) equals (3  163) + (11 * 162) + (10  161) + (4  160), or 15,268(10)
o Calculating hexadecimal values up to 8 digits long:
Converting Decimal to Hexadecimal
Decimal 422(10) = 1A6(16) hexadecimal
CMPS293
5
Chapter 1
© Wendy Zhang, Computer Science & IT Department

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
1
1
36
28
28
6A
+ 42
45
58
4B
78
6D
80
B5
21 / 16 = 1, rem 5


Hexadecimal Subtraction
When a borrow is required from the digit to the left, add 16 (decimal) to the current
digit's value:
16 + 5 = 21
-1
C6
75
_A2
47
24
2E
Signed Integers
o The highest bit indicates the sign. 1 = negative,
0 = positive
sign bit
1
1
1
1
0
1
1
0
0
0
0
0
1
0
1
0
Negative
Positive
o If the highest digit of a hexadecimal integer is > 7, the value is negative. Examples:
8A, C5, A2, 9D
o Forming the Two's Complement
 Negative numbers are stored in two's complement notation
 Represents the additive Inverse
Note: 00000001(2) + 11111111(2) = 00000000(2)
CMPS293
6
Chapter 1
© Wendy Zhang, Computer Science & IT Department






Binary Subtraction
o When subtracting A – B, convert B to its two's complement
o Add A to (–B)
00001100
00001100
–
00000011
+ 11111101
00001001
Form the two's complement of a hexadecimal integer
o Reverse all bits and add 1
o Easy way: subtract the digits from 15 and add 1
6A3D(16) → 95C2(16)→ 95C3
Convert signed binary to decimal
o If the highest bit is a 1, the number is in two’s complement
 Form two’s complement
 Convert decimal number and attach a minus sign to the beginning of the integer
Starting value
11110000(2)
Step 1: Reverse the bits
00001111
Step 2: Add 1 to the value from step 1
00001111
+
1
Step 3: Form the two’s complement
00010000
Step 4: Covert to decimal and attach sign
- 16(10)
o If the highest bit is a 0, convert it to decimal integer
Convert signed decimal to binary
o Convert the absolute value into binary
o If the original decimal number is negative, form the two’s complement of the binary
number
Starting value
-16(10)
Step 1: Convert the absolute value into binary
00010000(2)
Step 2: Reverse the bits
11101111(2)
Step 3: Form the two’s complement
11110000(2)
Convert signed decimal to hexadecimal
o Convert the absolute value into hexadecimal
o If the original decimal number is negative, form the two’s complement of the
hexadecimal number
Starting value
-43(10)
Step 1: Convert the absolute value into hexadecimal
2B(16)
Step 2: Form the two’s complement
D5(16)
Convert signed hexadecimal to decimal
o If the hexadecimal integer is negative, form it’s two’s complement otherwise retain
the integer as is
o Convert it to decimal number. If the original value is negative, attach a minus sign to
the beginning of the decimal integer
Starting value
D5(16)
Step 1: Form the two’s complement
2B(16)
Step 4: Covert to decimal and attach sign
- 43(10)
CMPS293
7
Chapter 1
© Wendy Zhang, Computer Science & IT Department

Ranges of Signed Integers

Character Storage
o Character sets
 Standard ASCII (American Standard Code for Information Interchange) (0 – 127)
 Extended ASCII (0 – 255)
 ANSI (American National Standard Institute) (0 – 255)
 Unicode (0 – 65,535)
o Null-terminated String
Array of characters followed by a null byte
o Using the ASCII table - back inside cover of book
Numeric Data Representation
o pure binary
can be calculated directly
o ASCII binary
string of digits: "01010101"
o ASCII decimal
string of digits: "65"
o ASCII hexadecimal
string of digits: "9C"

CMPS293
8
Chapter 1
© Wendy Zhang, Computer Science & IT Department
4. Boolean Operations
 Boolean Algebra
o Based on symbolic logic, designed by George Boole
o Boolean expressions created from: NOT, AND, OR

NOT
o Inverts (reverses) a boolean value
o Truth table for Boolean NOT operator:
Digital gate diagram for NOT:
o Digital gate diagram for NOT:
NOT

AND
o Truth table for Boolean AND operator:
Digital gate diagram for AND:
o Digital gate diagram for AND:
AND

OR
o Truth table for Boolean OR operator:
CMPS293
9
Chapter 1
© Wendy Zhang, Computer Science & IT Department
o Digital gate diagram for OR:
Digital gate diagram for OR:
OR

Digital gate diagram for OR:
Operator Precedence
OR



A Boolean function has one or more Boolean inputs, and returns a single Boolean output.
A truth table shows all the inputs and outputs of a Boolean function
Example: (Y  S)  (X  S)
Two-input multiplexer:
S
X
mux
Z
Y
Two-input multiplexer
CMPS293
10
Chapter 1
Download