chap 01[1]
TRANSCRIPT
Chapter 1: Context of Assembly Language
Copyright 1999-2000, Prentice-Hall Incorporated
Updated 08/00
Slides to Accompany
Assembly Language for Intel-Based Computers,
Third Edition
Table 1. Software Hierarchy Levels.
Level Description
Application ProgramSoftware designed for a particular class ofapplications.
High-Level Language (HLL)
Programs are compiled into either assembly languageor machine language. Each statement usuallytranslates into multiple machine language instructions.Examples are C++, Pascal, Java, and Visual Basic.
Operating System
Contains procedures that can be called from programswritten in either high-level language or assemblylanguage. This system may also contain an applicationprogramming interface (API).
Assembly Language (ASM)Uses instruction mnemonics that have a one-to-onecorrespondence with machine language.
Machine Language (ML)Numeric instructions and operands that can be storedin memory and directly executed by the computerprocessor.
Essential Tools
• An assembler is a program that converts source-code
programs into a machine language (object file).
• A linker joins together two or more object files and
produces a single executable file.
• A debugger loads an executable program, displays
the source code, and lets the programmer step
through the program one instruction at a time, and
display and modify memory.
Table 2. Comparison of Assembly Language to HLLs.
Type of Application High-Level Language Assembly Language
Business applicationsoftware, written forsingle platform, mediumto large size.
Formal structures make iteasy to organize andmaintain large sections ofcode.
No formal structure.Programmer must impose anartificial structure.
Hardware device driver. Language may not providefor direct hardware access.Awkward coding techniquesmust be used, resulting inpossible maintenanceproblems.
Hardware access isstraightforward and simple.Easy to maintain when theprograms are short and welldocumented.
Business applicationwritten for multipleplatforms (differentoperating systems).
Usually very portable. Thesource code can berecompiled on each targetoperating system withminimal changes.
Must be recoded separatelyfor each platform, oftenusing an assembler with adifferent syntax. Difficult tomaintain.
Embedded systems andcomputer gamesrequiring directhardware access.
Produces too muchexecutable code, and maynot run efficiently.
Ideal, because theexecutable code is smalland runs quickly.
Figure 2. Assembly Language Subroutines Used as Hardware Interfaces.
ApplicationProgram
InterfaceSubroutine
OperatingSystem
Device DriverSubroutine
Hardware
Machine Language
• Consists of binary numbers• The "native" language of the computer• Each ML instruction contains an op code (operation
code) and zero or more operands. • Examples:
Opcode Operand Meaning-------------------------------------------------40 increment the AX register05 0005 add 0005 to AX
Page 7: Bits, Bytes, and Doublewords:
byte byte
wordbit01 000 10 1 10 1 010 10
Each 1 or 0 is called a bit.
Storage Type Bits Range (low - high)
Unsigned byte 8 0 to 255
Unsigned word 16 0 to 65,535
Unsigned doubleword 32 0 to 4,294,967,295
Unsigned quadword 64 0 to 18,446,744,073,709,551,615
Table 3. Storage Sizes and Ranges of Unsigned Integers.
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
Table 4. Digits in Various Number Systems.
Format Value
ASCII binary "01000001"
ASCII decimal "65"
ASCII hexadecimal "41"
ASCII octal "101"
Page 9. ASCII Digit String.
2n Decimal Value 2n Decimal Value
20 1 28 256
21 2 29 512
22 4 210 1024
23 8 211 2048
24 16 212 4096
25 32 213 8192
26 64 214 16384
27 128 215 32768
Table 5. Binary Bit Position Values.
Binary Decimal Hexadecimal Binary Decimal Hexadecimal
0000 0 0 1000 8 8
0001 1 1 1001 9 9
0010 2 2 1010 10 A
0011 3 3 1011 11 B
0100 4 4 1100 12 C
0101 5 5 1101 13 D
0110 6 6 1110 14 E
0111 7 7 1111 15 F
Table 6. Binary, Decimal, and Hexadecimal Equivalents.
Table 7. Powers of 16, in Decimal.
16n Decimal Value 16n Decimal Value
160 1 164 65,536
161 16 165 1,048,576
162 256 166 16,777,216
163 4096 167 268,435,456
3 * 4096 = 12,288
11 * 256 = 2,816
10 * 16 = 160
4 * 1 = + 4
Total: 15,268
4AB3
Figure 4. Converting 3BA4 Hexadecimal to Decimal.
Table 8. Signed Integer Storage and Ranges.
Storage Type Bits Range (low - high)
Signed byte 7 -128 to +127
Signed word 15 –32,768 to +32,767
Signed doubleword 31 –2,147,483,648 to 2,147,483,647
Signed quadword 63 –9,223,372,036,854,775,808 to+9,223,372,036,854,775,807
00110001 00110010 00110011
01111011
123
' 1 ' ' 2 ' ' 3 '
=
=
"1 2 3"
1 2 3
1.2.5 Character Storage
Page 14. ASCII Representation of 123:
1.3 Introducing Assembly Language
• An instruction is a symbolic representation of a single machine instruction
• Consists of:– label always optional– mnemonic always required– operand(s) required by some instructions– comment always optional
• Examples:
start: mov ax,20 ; initialize the AX register
inc bx ; increment the BX register
stc ; set the Carry flag
1.
2.
3.
4.
mov ax, 5
add ax, 10
add ax, 20
mov [0120], ax ax
ax
ax
ax 05
15
35
35
Memory
35 0120
5. int 20
011E
011C
0122
0124
0126
Figure 5. Sample Program Written in Debug.
Running DEBUG.EXE, Assembling a Program
C:\>debug
-A 100
0AFE:0100 mov ax,5
0AFE:0103 add ax,10
0AFE:0106 add ax,20
0AFE:0109 mov [120],ax
0AFE:010C int 20
0AFE:010E
assemble, starting at offset 100
Press ENTER to return to command mode
Tracing the Sample Program.
-T
AX=0005 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0103 NV UP EI PL NZ NA PO NC
0AFE:0103 051000 ADD AX,0010
-T
AX=0015 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0106 NV UP EI PL NZ NA PO NC
0AFE:0106 052000 ADD AX,0020
-T
AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=0109 NV UP EI PL NZ NA PE NC
0AFE:0109 A32001 MOV [0120],AX
Tracing the Sample Program (2)
MOV [0120],AX
-D 120,121
0AFE:0120 35 00
AX=0035 BX=0000 CX=0000 DX=0000 SP=FFEE BP=0000 SI=0000 DI=0000
DS=0AFE ES=0AFE SS=0AFE CS=0AFE IP=010C NV UP EI PL NZ NA PE NC
0AFE:010C CD20 INT 20
-G
Program terminated normally
Table 9. Commonly Used Debug Commands.
Command Description
A Starts assembling a program, placing each instruction inmemory. Optionally, an integer argument can besupplied, which specifies the hexadecimal locationwhere the first instruction is to be inserted.
G Executes the remainder of the program.
Q Quits Debug
R Displays the CPU registers.
T Traces (execute) one program instruction.