Assembly Language For Intel-Based Computers, 4 Edition
Assembly Language For Intel-Based Computers, 4 Edition
Chapter Overview
Web site
Examples
Integer constants
Integer expressions
Character and string constants
Reserved words and identifiers
Directives and instructions
Labels
Mnemonics and Operands
Comments
Examples
Web site
Examples
Integer Constants
Optional leading + or sign
binary, decimal, hexadecimal, or octal digits
Common radix characters:
h hexadecimal
d decimal
b binary
r encoded real
Web site
Examples
Integer Expressions
Operators and precedence levels:
Examples:
Web site
Examples
Embedded quotes:
'Say "Goodnight," Gracie'
Web site
Examples
Identifiers
1-247 characters, including digits
case insensitive (by default)
first character must be a letter, _, @, or $
Directives
command understood by the assembler
not part of Intel instruction set
case insensitive
Web site
Examples
Directives
Commands that are recognized and acted
upon by the assembler
Not part of the Intel instruction set
Used to declare code, data areas, select
memory model, declare procedures, etc.
Web site
Examples
Instructions
Label
Mnemonic
Operand
Comment
Web site
Examples
Labels
Act as place markers
marks the address (offset) of code and data
Code label
target of jump and loop instructions
example: L1:
(followed by colon)
Web site
Examples
10
Operands
Web site
Examples
11
Comments
Comments are good!
Single-line comments
begin with semicolon (;)
Multi-line comments
begin with COMMENT directive and a programmerchosen character
end with the same programmer-chosen character
Web site
Examples
12
One operand
inc eax
inc myByte
; register
; memory
Two operands
add ebx,ecx
sub myByte,25
add eax,36 * 25
; register, register
; memory, constant
; register, constant-expression
Web site
Examples
13
(AddSub.asm)
;
;
;
;
EAX = 10000h
EAX = 50000h
EAX = 30000h
display registers
Web site
Examples
14
Example Output
Program output, showing registers and flags:
EAX=00030000
EBX=7FFDF000
ECX=00000101
EDX=FFFFFFFF
ESI=00000000
EDI=00000000
EBP=0012FFF0
ESP=0012FFC4
EIP=00401024
EFL=00000206
CF=0
SF=0
Web site
ZF=0
Examples
OF=0
15
(1 of 2)
Other suggestions
descriptive identifier names
spaces surrounding arithmetic operators
blank lines between procedures
Web site
Examples
16
(2 of 2)
Web site
Examples
17
(AddSubAlt.asm)
; EAX = 10000h
; EAX = 50000h
; EAX = 30000h
Web site
Examples
18
Program Template
TITLE Program Template
;
;
;
;
;
(Template.asm)
Program Description:
Author:
Creation Date:
Revisions:
Date:
Modified by:
Instructors: please
customize as needed
INCLUDE Irvine32.inc
.data
; (insert variables here)
.code
main PROC
; (insert executable instructions here)
exit
main ENDP
; (insert additional procedures here)
END main
Web site
Examples
19
Assemble-Link-Execute Cycle
make32.bat
Listing File
Map File
Web site
Examples
20
Web site
Examples
21
make32.bat
Called a batch file
Run it to assemble and link programs
Contains a command that executes ML.EXE (the
Microsoft Assembler)
Contains a command that executes LINK32.EXE (the
32-bit Microsoft Linker)
Command-Line syntax:
make32 progName
Web site
Examples
22
Listing File
Use it to see how your program is compiled
Contains
source code
addresses
object code (machine language)
segment names
symbols (variables, procedures, and constants)
Example: addSub.lst
Web site
Examples
23
Map File
Information about each program segment:
starting address
ending address
size
segment type
Example: addSub.map
Web site
Examples
24
Defining Data
Web site
Examples
25
WORD, SWORD
16-bit unsigned & signed integer
DWORD, SDWORD
32-bit unsigned & signed integer
QWORD
64-bit integer
TBYTE
80-bit integer
Web site
Examples
26
REAL8
8-byte IEEE long real
REAL10
10-byte IEEE extended real
Web site
Examples
27
Web site
Examples
28
; character constant
value2 BYTE 0
value6 BYTE ?
; uninitialized byte
Web site
Examples
29
Defining Bytes
Examples that use multiple initializers:
list1 BYTE 10,20,30,40
list2 BYTE 10,20,30,40
BYTE 50,60,70,80
BYTE 81,82,83,84
list3 BYTE ?,32,41h,00100010b
list4 BYTE 0Ah,20h,A,22h
Web site
Examples
30
Defining Strings
(1 of 3)
Examples:
str1 BYTE
str2 BYTE
str3 BYTE
greeting
Web site
Examples
31
Defining Strings
(2 of 3)
Web site
Examples
32
Defining Strings
(3 of 3)
Web site
Examples
33
; 20 bytes, uninitialized
; 20 bytes: "STACKSTACKSTACKSTACK"
Web site
Examples
34
;
;
;
;
;
;
Web site
Examples
35
DWORD 12345678h
SDWORD 2147483648
DWORD 20 DUP(?)
SDWORD 3,2,1,0,1
;
;
;
;
unsigned
signed
unsigned array
signed array
Web site
Examples
36
Web site
Examples
37
Web site
Examples
38
Web site
Examples
39
Web site
Examples
40
Symbolic Constants
Equal-Sign Directive
Calculating the Sizes of Arrays and Strings
EQU Directive
TEXTEQU Directive
Web site
Examples
41
Equal-Sign Directive
name = expression
expression is a 32-bit integer (expression or constant)
may be redefined
name is called a symbolic constant
Web site
Examples
42
Web site
Examples
43
Web site
Examples
44
Web site
Examples
45
EQU Directive
Define a symbol as either an integer or text expression.
Cannot be redefined
PI EQU <3.1416>
pressKey EQU <"Press any key to continue...",0>
.data
prompt BYTE pressKey
Web site
Examples
46
TEXTEQU Directive
Define a symbol as either an integer or text expression.
Called a text macro
Can be redefined
continueMsg TEXTEQU <"Do you wish to continue (Y/N)?">
rowSize = 5
.data
prompt1 BYTE continueMsg
count TEXTEQU %(rowSize * 2)
Web site
Examples
47
(1 of 2)
Disadvantages
must be aware of both segments and offsets
cannot call Win32 functions (Windows 95 onward)
limited to 640K program memory
Web site
Examples
48
(2 of 2)
Requirements
INCLUDE Irvine16.inc
Initialize DS to the data segment:
mov ax,@data
mov ds,ax
Web site
Examples
49
Web site
Examples
50
46 69 6E 69 73
Web site
Examples
51