x86 Assembly Language. Reference Manual (1995) - page 1

 

  Главная      Manuals     x86 Assembly Language. Reference Manual (1995)

 

Search            copyright infringement  

 

 

 

 

 

 

 

 

 

 

 

Content      ..      1       2         ..

 

 

 

x86 Assembly Language. Reference Manual (1995) - page 1

 

 

x86 Assembly Language
Reference Manual
2550 Garcia Avenue
Mountain View, CA 94043
U.S.A.
A Sun Microsystems, Inc. Business
Contents
Preface
xvii
1. Assembler Input
1
Introduction
1
Source Files in Assembly Language Format
2
File Organization
2
Statements
3
Values and Symbol Types
4
Expressions
6
Expression Syntax
7
Expression Semantics (Absolute vs. Relocatable)
9
Machine Instruction Syntax
10
Instruction Description
12
Pseudo Operations
14
General Pseudo Operations
14
Symbol Definition Pseudo Operations
19
iii
2.
Instruction-Set Mapping
21
Introduction
22
Notational Conventions
23
References
26
Segment Register Instructions
26
Load Full Pointer (lds,les, lfs, lgs, and lss)
26
Pop Stack into Word (pop)
27
Push Word/Long onto Stack (push)
28
I/O Instructions
29
Input from Port (in, ins)
29
Output from Port (out, outs)
31
Flag Instructions
32
Load Flags into AH Register (lahf)
32
Store AH into Flags (sahf)
33
Pop Stack into Flag (popf)
33
Push Flag Register Onto Stack (pushf)
34
Complement Carry Flag (cmc)
35
Clear Carry Flag (clc)
35
Set Carry Flag (stc)
36
Clear Interrupt Flag (cli)
36
Set Interrupt Flag (sti)
37
Clear Direction Flag (cld)
37
Set Direction Flag (std)
38
Arithmetic Logical Instructions
38
iv
x86 Assembly Language Reference Manual—November 1995
Integer Addition (add)
38
Integer Add With Carry (adc)
39
Integer Subtraction (sub)
40
Integer Subtraction With Borrow (sbb)
41
Compare Two Operands (cmp)
42
Increment by 1 (inc)
43
Decrease by 1 (dec)
44
Logical Comparison or Test (test)
45
Shift (sal, shl, sar, shr)
46
Double Precision Shift Left (shld)
48
Double Precision Shift Right (shrd)
49
One’s Complement Negation (not)
50
Two’s Complement Negation (neg)
50
Check Array Index Against Bounds (bound)
51
Logical And (and)
52
Logical Inclusive OR (or)
54
Logical Exclusive OR (xor)
55
Multiply and Divide Instructions
56
Signed Multiply (imul)
57
Unsigned Multiplication of AL, AX or EAX(mul)
58
Unsigned Divide (div)
60
Signed Divide (idiv)
61
Conversion Instructions
62
Convert Byte to Word (cbtw)
62
Contents
v
Convert Word to Long (cwtl)
63
Convert Signed Word to Signed Double Word (cwtd)
63
Convert Signed Long to Signed Double Long (cltd)
64
Decimal Arithmetic Instructions
64
Decimal Adjust AL after Addition (daa)
64
Decimal Adjust AL after Subtraction (das)
65
ASCII Adjust after Addition (aaa)
65
ASCII Adjust after Subtraction (aas)
66
ASCII Adjust AX after Multiply (aam)
67
ASCII Adjust AX before Division (aad)
68
Coprocessor Instructions
69
Wait (wait, fwait)
69
String Instructions
69
Move Data from String to String (movs)
70
Compare String Operands (cmps)
71
Store String Data (stos)
72
The Load String Operand (lods)
73
Compare String Data (scas)
75
Look-Up Translation Table (xlat)
76
Repeat String Operation (rep, repnz, repz)
77
Procedure Call and Return Instructions
78
Far Call — Procedure Call (lcall)
78
Near Call — Procedure Call (call)
79
Return from Procedure (ret)
80
vi
x86 Assembly Language Reference Manual—November 1995
Long Return (lret)
81
Enter/Make Stack Frame for Procedure Parameters (enter)
82
High Level Procedure Exit (leave)
83
Jump Instructions
83
Jump if ECX is Zero (jcxz)
83
Loop Control with CX Counter (loop, loopnz, loopz)
84
Jump (jmp, ljmp)
85
Interrupt Instructions
87
Call to Interrupt Procedure (int, into)
87
Interrupt Return (iret)
89
Protection Model Instructions
90
Store Local Descriptor Table Register (sldt)
90
Store Task Register (str)
90
Load Local Descriptor Table Register (lldt)
91
Load Task Register (ltr)
92
Verify a Segment for Reading or Writing (verr, verw)
92
Store Global/Interrupt Descriptor Table Register (sgdt, sidt)
93
Load Global/Interrupt Descriptor Table (lgdt, lidt)
94
Store Machine Status Word (smsw)
95
Load Machine Status Word (lmsw)
96
Load Access Rights (lar)
96
Load Segment Limit (lsl)
97
Clear Task-Switched (clts)
98
Adjust RPL Field of Selector (arpl)
99
Contents
vii
Bit Instructions
100
Bit Scan Forward (bsf)
100
Bit Scan Reverse (bsr)
100
Bit Test (bt)
101
Bit Test And Complement (btc)
102
Bit Test And Reset (btr)
102
Bit Test And Set (bts)
103
Exchange Instructions
103
Compare and Exchange (cmpxchg)[486]
103
Floating-Point Transcendental Instructions
104
Floating-Point Sine (fsin)
104
Floating-Point Cosine (fcos)
104
Floating-Point Sine and Cosine (fsincos)
104
Floating-Point Constant Instructions
105
Floating-Point Load One (fld)
105
Processor Control Floating-Point Instructions
105
Floating-Point Load Control Word (fldcw)
105
Floating-Point Load Environment (fldenv)
106
Miscellaneous Floating-Point Instructions
106
Floating-Point Different Reminder (fprem)
106
Floating-Point Comparison Instructions
106
Floating-Point Unsigned Compare (fucom)
106
Floating-Point Unsigned Compare And Pop (fucomp) . . .
107
Floating-Point Unsigned Compare And Pop Two (fucompp)107
viii
x86 Assembly Language Reference Manual—November 1995
Load and Move Instructions
108
Load Effective Address (lea)
108
Move (mov)
109
Move Segment Registers (movw)
109
Move Control Registers (mov)
110
Move Debug Registers (mov)
111
Move Test Registers (mov)
111
Move With Sign Extend (movsx)
112
Move With Zero Extend (movzb)
112
Pop Instructions
113
Pop All General Registers (popa)
113
Push Instructions
114
Push All General Registers (pusha)
114
Rotate Instructions
114
Rotate With Carry Left (rcl)
114
Rotate With Carry Right (rcr)
115
Rotate Left (rol)
116
Rotate Right (ror)
117
Byte Instructions
118
Byte Set On Condition (setcc)
118
Byte Swap (bswap) [486]
120
Exchange Instructions
120
Exchange And Add (xadd) [486]
120
Exchange Register / Memory With Register (xchg)
120
Contents
ix
Miscellaneous Instructions
121
Write Back and Invalidate Cache (wbinvd) [486 only]
121
Invalidate (invd) [486 only]
122
Invalidate Page (invlpg) [486 only]
122
LOCK Prefix (lock)
122
No Operation (nop)
123
Halt (hlt)
124
Real Transfer Instructions
125
Load Real (fld)
125
Store Real (fst)
125
Store Real and Pop (fstp)
126
Exchange Registers (fxch)
126
Integer Transfer Instructions
127
Integer Load (fild)
127
Integer Store (fist)
127
Integer Store and Pop (fistp)
127
Packed Decimal Transfer Instructions
128
Packed Decimal (BCD) Load (fbld)
128
Packed Decimal (BCD) Store and Pop (fbstp)
128
Addition Instructions
129
Real Add (fadd)
129
Real Add and Pop (faddp)
129
Integer Add (fiadd)
129
Subtraction Instructions
130
x
x86 Assembly Language Reference Manual—November 1995
Subtract Real and Pop (fsub)
130
Subtract Real (fsubp)
130
Subtract Real Reversed (fsubr)
130
Subtract Real Reversed and Pop (fsubrp)
131
Integer Subtract (fisubrp)
131
Integer Subtract Reverse (fisubr)
131
Multiplication Instructions
132
Multiply Real (fmul)
132
Multiply Real and Pop (fmulp)
132
Integer Multiply (fimul)
132
Division Instructions
133
Divide Real (fdiv)
133
Divide Real and Pop (fdivp)
133
Divide Real Reversed (fdivr)
133
Divide Real Reversed and Pop (fdivrp)
134
Integer Divide (fidiv)
134
Integer Divide Reversed (fidivr)
134
Miscellaneous Arithmetic Operations
136
Square Root (fsqrt)
136
Scale (fscale)
136
Partial Remainder (fprem)
136
Round to Integer (frndint)
137
Extract Exponent and Significand (fxtract)
137
Absolute Value (fabs)
137
Contents
xi
Change Sign (fchs)
138
Comparison Instructions
138
Compare Real (fcom)
138
Compare Real and Pop (fcomp)
139
Compare Real and Pop Twice (fcompp)
139
Integer Compare (ficom)
139
Integer Compare and Pop (ficomp)
140
Test (ftst)
140
Examine (fxam)
140
Transcendental Instructions
141
Partial Tangent (fptan)
141
Partial Arctangent (fpatan)
142
2x - 1 (f2xm1)
142
Y * log2 X (fyl2x)
142
Y * log2 (X+1) (fyl2xp1)
143
Constant Instructions
143
Load log2 E (fldl2e)
143
Load log2 10 (fldl2t)
143
Load log10 2 (fldlg2)
144
Load loge 2 (fldln2)
144
Load pi (fldpi)
144
Load + 0 (fldz)
145
Processor Control Instructions
145
Initialize Processor (finit, fnint)
145
xii
x86 Assembly Language Reference Manual—November 1995
No Operation (fnop)
145
Save State (fsave, fnsave)
146
Store Control Word (fstcw, fnstcw)
146
Store Environment (fstenv, fnstenv)
146
Store Status Word (fstsw, fnstsw)
147
Restore State (frstor)
147
CPU Wait (fwait, wait)
147
Clear Exceptions (fclex, fnclex)
148
Decrement Stack Pointer (fdecstp)
148
Free Registers (ffree)
148
Increment Stack Pointer (fincstp)
149
3.
Assembler Output
151
Introduction
151
Object Files in Executable and Linking Format (ELF)
152
ELF Header
153
Section Header
155
Sections
159
Symbol Tables
162
String Tables
164
A.
Using the Assembler Command Line
167
Assembler Command Line
167
Assembler Command Line Options
168
Disassembling Object Code
169
Index
171
Contents
xiii
xiv
x86 Assembly Language Reference Manual—November 1995
Tables
Table 1-1
Object File Sections
6
Table 1-2
Operators Supported by the Assembler
6
Table 1-3
Syntactical Rules of Expressions
8
Table 1-4
8-bit (byte) General Registers
11
Table 1-5
16-bit (word) General Registers
11
Table 1-6
32-bit (long ) General Registers
12
Table 1-7
Description of Segment Registers
12
Table 2-1
Condition Codes
25
Table 2-2
Logical AND
53
Table 2-3
Inclusive OR
54
Table 2-4
Exclusive XOR
56
Table 2-5
Clearing OF and CF flags — imul
57
Table 2-6
Clearing OF and CF flags — mul
59
Table 2-7
idiv Register Assignment
62
Table 2-8
Handling a Carry
66
Table 2-9
How aas Handles a Carry
67
xv
Table 2-10
setcc Condition List
119
Table 2-11
Floating-point Opcodes
135
Table 3-1
Object File Types
155
Table 3-2
Section Attribute Flags
157
Table 3-3
Section Types
157
Table 3-4
Predefined User Sections
161
Table 3-5
Predefined Non-User Sections
161
Table 3-6
Symbol Types
164
Table 3-7
Symbol Bindings
164
xvi
x86 Assembly Language Reference Manual—November 1995
Preface
This preface is a brief description of the SunOS™ assembler that runs on x86.
This preface also includes a list of documents that can be used for reference.
The SunOS assembler that runs on x86, referred to as the “SunOS x86” in this
manual, translates source files that are in assembly language format into object
files in linking format.
In the program development process, the assembler is a tool to use in
producing program modules intended to exploit features of the Intel®
architecture in ways that cannot be easily done using high level languages and
their compilers.
Whether assembly language is chosen for the development of program
modules depends on the extent to which and the ease with which the language
allows the programmer to control the architectural features of the processor.
The assembly language described in this manual offers full direct access to the
x86 instruction set. The assembler may also be used in connection with SunOS
5.1 macro preprocessors to achieve full macro-assembler capability.
Furthermore, the assembler responds to directives that allow the programmer
direct control over the contents of the relocatable object file.
This document describes the language in which the source files must be
written. The nature of the machine mnemonics governs the way in which the
program’s executable portion is written. This document includes descriptions
of the pseudo operations that allow control over the object file. This facilitates
the development of programs that are easy to understand and maintain.
xvii
Before You Read This Book
Use the following documents as references:
Intel 80386 Programmer’s Reference Manual
i486™ Microprocessor Programmer Reference Manual (1990)
Intel 80387 Programmer’s Reference Manual (1987)
System V Application Binary Interface Intel 386 Processor Supplement
System V Application Binary Interface
SVID System V Interface Definition
You should also become familiar with the following:
Man pages: as(1), ld(1), cpp(1), mn(4),cof2elf(1) (elf - Executable and
Linking Format), elf(3E), dis(1), a.out(5).
ELF-related sections of the Programming Utilities manual.
How This Book Is Organized
This document is organized into the following chapters:
Chapter 1, “Assembler Input,” describes the overall structure required by the
assembler for input source files.
Chapter 2, “Instruction-Set Mapping,” describes the instruction set mappings
for the SunOS x86 processor.
Chapter 3, “Assembler Output,” provides an overview of ELF (Executable and
Linking Format) for the relocatable object files produced by the assembler.
Appendix A, “Using the Assembler Command Line,” describes the assembler
command line options.
xviii
x86 Assembly Language Reference Manual—November 1995
What Typographic Changes Mean
The following table describes the typographic changes used in this book.
Table P-1
Typographic Conventions
Typeface or
Symbol
Meaning
Example
AaBbCc123
The names of commands,
Edit your .login file.
files, and directories;
Use ls
-a to list all files.
on-screen computer output
machine_name% You have mail.
AaBbCc123
What you type, contrasted
machine_name% su
with on-screen computer
Password:
output
AaBbCc123
Command-line placeholder:
To delete a file, type rm filename.
replace with a real name or
value
AaBbCc123
Book titles, new words or
Read Chapter 6 in User’s Guide.
terms, or words to be
These are called class options.
emphasized
You must be root to do this.
Shell Prompts in Command Examples
The following table shows the default system prompt and superuser prompt
for the C shell, Bourne shell, and Korn shell.
Table P-2
Shell Prompts
Shell
Prompt
C shell prompt
machine_name%
C shell superuser prompt
machine_name#
Bourne shell and Korn shell
$
prompt
Bourne shell and Korn shell
#
superuser prompt
Preface
xix
xx
x86 Assembly Language Reference Manual—November 1995
Assembler Input
1
The SunOS x86 assembler translates source files in the assembly language
format specified in this document into relocatable object files for processing by
the link editor. This translation process is called assembly. The main input
required to assemble a source file in assembly language format is that source
file itself.
This chapter has the following organization:
Introduction
page 1
Source Files in Assembly Language Format
page 2
Pseudo Operations
page 14
Introduction
In whatever manner it is produced, the source input file must have a certain
structure and content. The specification of this structure and content
constitutes the syntax of the assembly language. A source file may be produced
by one of the following:
A programmer using a text editor
A compiler as an intermediate step in the process of translating from a high-
level language to executable code
An automatic program generator
Some other mechanism.
1
1
The assembler may also allow ancillary input incidental to the translation
process. For example, there are several invocation options available. Each such
option exercised constitutes information input to the assembler. However, this
ancillary input has little direct connection to the translation process, so it is not
properly a subject for this manual. Information about invoking the assembler
and the available options appears in the as(1) man pages.
This chapter describes the overall structure required by the assembler for input
source files. This structure is relatively simple: the input source file must be a
sequence of assembly language statements. This chapter also begins the
specification of the contents of the input source file by describing assembly
language statements as textual objects of a certain form.
This document completes the specification by presenting detailed assembly
language statements that correspond to the Intel instruction set and are
intended for use on machines that run SunOS x86 architecture. For more
information on assembly language instruction sets, please refer to the product
documentation from Intel Corporation.
Source Files in Assembly Language Format
This section details the following:
file organization
statements
values and symbols
expressions
machine instruction syntax
File Organization
Input to the assembler is a text file consisting of a sequence of statements. Each
statement ends with the first occurrence of a newline character (ASCII LF), or
of a semicolon (;) that is not within a string operand or between a slash and a
newline character. Thus, it is possible to have several statements on one line.
2
x86 Assembly Language Reference Manual—November 1995
1
To make programs easy to read, understand and maintain, however, it is good
programming practice not to have more than one statement per line. As
indicated above, a line may contain one or more statements. If several
statements appear on a line, they must be separated by semicolons (;).
Statements
This section outlines the types of statements that apply to assembly language.
Each statement must be one of the following types:
An empty statement is one that contains nothing other than spaces, tabs, or
formfeed characters.
Empty statements have no meaning to the assembler. They can be inserted
freely to improve the appearance of a source file or of a listing generated
from it.
An assignment statement is one that gives a value to a symbol. It consists of
a symbol, followed by an equal sign (=), followed by an expression.
The expression is evaluated and the result is assigned to the symbol.
Assignment statements do not generate any code. They are used only to
assign assembly time values to symbols.
A pseudo operation statement is a directive to the assembler that does not
necessarily generate any code. It consists of a pseudo operation code,
optionally followed by operands. Every pseudo operation code begins with
a period (.).
A machine operation statement is a mnemonic representation of an executable
machine language instruction to which it is translated by the assembler. It
consists of an operation code, optionally followed by operands.
Furthermore, any statement remains a statement even if it is modified in either
or both of the following ways:
Prefixing a label at the beginning of the statement.
A label consists of a symbol followed by a colon (:). When the assembler
encounters a label, it assigns the value of the location counter to the label.
Appending a comment at the end of the statement by preceding the
comment with a slash (/).
Assembler Input
3
1
The assembler ignores all characters following a slash up to the next
occurrence of newline. This facility allows insertion of internal program
documentation into the source file for a program.
Values and Symbol Types
This section presents the values and symbol types that the assembler uses.
Values
Values are represented in the assembler by numerals which can be faithfully
represented in standard two’s complement binary positional notation using 32
bits. All integer arithmetic is performed using 32 bits of precision. Note,
however, that the values used in an x86 instruction may require 8, 16, or 32
bits.
Symbols
A symbol has a value and a symbol type, each of which is either specified
explicitly by an assignment statement or implicitly from context. Refer to the
next section for the regular definition of the expressions of a symbol.
The following symbols are reserved by the assembler:
.Commonly referred to as dot. This is the location counter while assembling a
program. It takes on the current location in the text, data, or bss section.
.text
This symbol is of type text. It is used to label the beginning of a .text section
in the program being assembled.
.data
This symbol is of type data. It is used to label the beginning of a data section
in the program being assembled.
.bss
This symbol is of type bss. It is used to label the beginning of a .bss section
in the program being assembled.
4
x86 Assembly Language Reference Manual—November 1995
1
.init
This is used with C++ programs which require constructors.
.fini
This is used with C++ programs which require destructors.
Symbol Types
Symbol type is one of the following:
undefined
A value is of undefined symbol type if it has not yet been defined. Example
instances of undefined symbol types are forward references and externals.
absolute
A value is of absolute symbol type it does not change with relocation.
Example instances of absolute symbol types are numeric constants and
expressions whose proper sub-expressions are themselves all absolute.
text
A value is of text symbol type if it is relative to the .text section.
data
A value is of data symbol type if it is relative to the .data section.
bss
A value is of bss symbol type if it is relative to the .bss section.
You can give any of these symbol types the attribute EXTERNAL.
Sections
Five of the symbol types are defined with respect to certain sections of the
object file into which the assembler translates the source file. This section
describes symbol types.
Assembler Input
5
1
If the assembler translates a particular assembly language statement into a
machine language instruction or into a data allocation, the translation is
associated with one of the following five sections of the object file into which
the assembler is translating the source file:
Table 1-1
Object File Sections
Section
Purpose
text
This is an initialized section. Normally, it is read-only and
contains code from a program. It may also contain read-only
tables
data
This is an initialized section. Normally, it is readable and
writable. It contains initialized data. These can be scalars or
tables.
bss
This is an initialized section. Space is not allocated for this
segment in the object file.
init
This is used with C++ programs that require constructors.
fini
This is used by C++ programs that require destructors.
An optional section, .comment, may also be produced (see Chapter 3,
“Assembler Output”).
The section associated with the translated statement is .text unless the
original statement occurs after a section control pseudo operation has directed
the assembler to associate the statement with another section.
Expressions
The expressions accepted by the x86 assembler are defined by their syntax and
semantics. The following are the operators supported by the assembler:
Table 1-2
Operators Supported by the Assembler
Operator
Action
+
Addition
-
Subtraction
\*
Multiplication
\/
Division
6
x86 Assembly Language Reference Manual—November 1995
1
Table 1-2
Operators Supported by the Assembler
Operator
Action
&
Bitwise logical and
|
Bitwise logical or
>>
Right shift
<<
Left shift
\%
Remainder operator
!
Bitwise logical and not
Expression Syntax
Table 1-3 shows syntactic rules, the non terminals are represented by lowercase
letters, the terminal symbols are represented by uppercase letters, and the
symbols enclosed in double quotes are terminal symbols. There is no
precedence assigned to the operators. You must use square brackets to
establish precedence.
Assembler Input
7
1
Table 1-3
Syntactical Rules of Expressions
expr
: term
| expr "+" term
| expr "-" term
| expr "\*" term
| expr "\/" term
| expr "&" term
| expr "|" term
| expr ">>" term
| expr "<<" term
| expr "\%" term
| expr "!" term
;
term
: id
| number
| "-" term
| "[" expr "]"
| "<o>" term
| "<s>" term
;
id
: LABEL
;
number
: DEC_VAL
| HEX_VAL
| OCT_VAL
| BIN_VAL
;
The terminal nodes are given by the following regular expressions:
LABEL
= [a-zA-Z_][a-zA-Z0-9_]*:
DEC_VAL = [1-9][0-9]*
HEX_VAL = 0[Xx][0-9a-fA-F][0-9a-fA-F]*
OCT_VAL = 0[0-7]*
BIN_VAL = 0[Bb][0-1][0-1]*
8
x86 Assembly Language Reference Manual—November 1995
1
In the above regular expressions, choices are enclosed in square brackets; a
range of choices is indicated by letters or numbers separated by a dash (-); and
the asterisk (*) indicates zero or more instances of the previous character.
Expression Semantics (Absolute vs. Relocatable)
Semantically, the expressions fall into two groups, absolute and relocatable.
The equations later in this section show the legal combinations of absolute and
relocatable operands for the addition and subtraction operators. All other
operations are only legal on absolute-valued expressions.
All numbers have the absolute attribute. Symbols used to reference storage,
text, or data are relocatable. In an assignment statement, symbols on the left
side inherit their relocation attributes from the right side.
In the equations below, a is an absolute-valued expression and r is a
relocatable-valued expression. The resulting type of the operation is shown to
the right of the equal sign.
a + a = a
r + a = r
a - a = a
r - a = r
r - r = a
In the last example, you must declare the relocatable expressions before taking
their difference.
Following are some examples of valid expressions:
label
$label
[label + 0x100]
[label1 - label2]
$[label1 - label2]
Assembler Input
9
1
Following are some examples of invalid expressions:
[$label - $label]
[label1 * 5]
(label + 0x20)
Machine Instruction Syntax
This section describes the instructions that the assembler accepts. The detailed
specification of how the particular instructions operate is not included; for this,
see Intel’s 80386 Programmer’s Reference Manual.
The following list describes the three main aspects of the SunOS x86 assembler:
All register names use the percent sign (%) as a prefix to distinguish them
from symbol names.
Instructions with two operands use the left one as the source and the right
one as the destination. This follows the SunOS operating environment
assembler convention, and is reversed from Intel’s notation.
Most instructions that can operate on a byte, word, or long may have b, w, or
l appended to them. When an opcode is specified with no type suffix, it
usually defaults to long. In general, the SunOS assembler derives its type
information from the opcode, where the Intel assembler can derive its type
information from the operand types. Where the type information is derived
motivates the b, w, and l suffixes used in the SunOS assembler. For
example, in the instruction movw $1,%eax the w suffix indicates the operand
is a word.
Operands
Three kinds of operands are generally available to the instructions: register,
memory, and immediate. Full descriptions of each type appear in “Notational
Conventions” on page 23. Indirect operands are available only to jump and call
instructions.
The assembler always assumes it is generating code for a 32-bit segment. When
16-bit data is called for (e.g., movw
%ax, %bx), the assembler automatically
generates the 16-bit data prefix byte.
10
x86 Assembly Language Reference Manual—November 1995
1
Byte, word, and long registers are available on the x86 processor. The
instruction pointer (%eip) and flag register (%efl) are not available as explicit
operands to the instructions. The code segment (%cs) may be used as a source
operand but not as a destination operand.
The names of the byte, word, and long registers available as operands and a
brief description of each follow. The segment registers are also listed.
Table 1-4
8-bit (byte) General Registers
%al
Low byte of %ax register
%ah
High byte of %ax register
%cl
Low byte of %cx register
%ch
High byte of %cx register
%dl
Low byte of %dx register
%dh
High byte of %dx register
%bl
Low byte of %bx register
%bh
High byte of %bx register
Table 1-5
16-bit (word) General Registers
%ax
Low 16-bits of %eax register
%cx
Low 16-bits of %ecx register
%dx
Low 16-bits of %edx register
%bx
Low 16-bits of %ebx register
%sp
Low 16-bits of the stack pointer
%bp
Low 16-bits of the frame pointer
%si
Low 16-bits of the source index register
%di
Low 16-bits of the destination index register
Assembler Input
11
1
Table 1-6
32-bit (long ) General Registers
%eax
32-bit general register
%ecx
32-bit general register
%edx
32-bit general register
%ebx
32-bit general register
%esp
32-bit stack pointer
%ebp
32-bit frame pointer
%esi
32-bit source index register
%edi
32-bit destination index register
Table 1-7
Description of Segment Registers
%cs
Code segment register; all references to the instruction space
use this register
%ds
Data segment register, the default segment register for most
references to memory operands
%ss
Stack segment register, the default segment register for
memory operands in the stack (i.e., default segment register for
%bp, %sp, %esp, and %ebp)
%es
General-purpose segment register; some string instructions use
this extra segment as their default segment
%fs
General-purpose segment register
%gs
General-purpose segment register
Instruction Description
This section describes the SunOS x86 instruction syntax.
The assembler assumes it is generating code for a 32-bit segment, therefore, it
also assumes a 32-bit address and automatically precedes word operations
with a 16-bit data prefix byte.
12
x86 Assembly Language Reference Manual—November 1995
1
Addressing Modes
Addressing modes are represented by the following:
[sreg:][offset][([base][,index][,scale])]
All the items in the square brackets are optional, but at least one is
necessary. If you use any of the items inside the parentheses, the
parentheses are mandatory.
sreg is a segment register override prefix. It may be any segment register. If
a segment override prefix is present, you must follow it by a colon before
the offset component of the address. sreg does not represent an address by
itself. An address must contain an offset component.
offset is a displacement from a segment base. It may be absolute or
relocatable. A label is an example of a relocatable offset. A number is an
example of an absolute offset.
base and index can be any 32-bit register. scale is a multiplication factor
for the index register field. Its value may be 1, 2, 4, 8 to indicate the
number to multiply by. The multiplication then occurs by 1, 2, 4, and 8.
Refer to Intel’s 80386 Programmer’s Reference Manual for more details on x86
addressing modes.
Following are some examples of addresses:
movl var, %eax
Move the contents of memory location var into %eax.
movl %cs:var, %eax
Move the contents of the memory location var in the code segment into
%eax.
movl $var, %eax
Move the address of var into %eax.
movl array_base(%esi), %eax
Add the address of memory location array_base to the contents of %esi
to get an address in memory. Move the contents of this address into %eax.
Assembler Input
13
1
movl (%ebx, %esi, 4), %eax
Multiply the contents of %esi by 4 and add this to the contents of %ebx to
produce a memory reference. Move the contents of this memory location
into %eax.
movl struct_base(%ebx, %esi, 4), %eax
Multiply the contents of %esi by 4, add this to the contents of %ebx, and
add this to the address of struct_base to produce an address. Move the
contents of this address into %eax.
Expressions and Immediate Values
An immediate value is an expression preceded by a dollar sign:
immediate: "$" expr
Immediate values carry the absolute or relocatable attributes of their
expression component. Immediate values cannot be used in an expression,
and should be considered as another form of address, i.e., the immediate
form of address.
immediate: "$" expr "," "$" expr
The first expr is 16 bits of segment. The second expr is 32 bits of offset.
Pseudo Operations
The pseudo-operations listed in this section are supported by the x86
assembler.
General Pseudo Operations
Below is a list of the pseudo operations supported by the assembler. This is
followed by a separate listing of pseudo operations included for the benefit of
the debuggers (dbx(1)).
.align val
The align pseudo op causes the next data generated to be aligned modulo
val. val should be a positive integer value.
14
x86 Assembly Language Reference Manual—November 1995
1
.bcd val
The.bcd pseudo op generates a packed decimal (80-bit) value into the
current section. This is not valid for the.bss section. val is a nonfloating-
point constant.
.bss
The.bss pseudo op changes the current section to.bss.
.bss tag, bytes
Define symbol tag in the.bss section and add bytes to the value of dot
for.bss. This does not change the current section to.bss. bytes must be a
positive integer value.
.byte val [, val]
The.byte pseudo op generates initialized bytes into the current section.
This is not valid for.bss. Each val must be an 8-bit value.
.comm name, expr
[, alignment]
The.comm pseudo op allocates storage in the .data section. The storage is
referenced by the symbol name, and has a size in bytes of expr. expr
must be a positive integer. name cannot be predefined. If the alignment is
given, the address of the name is aligned to a multiple of alignments.
.data
The data pseudo op changes the current section to .data.
.double val
The .double pseudo op generates an 80387 64 bit floating-point constant
(IEEE 754) into the current section. Not valid in the .bss section. val is a
floating-point constant. val is a string acceptable to atof(3); that is, an
optional sign followed by a non-empty string of digits with optional
decimal point and optional exponent.
.even
The .even pseudo op aligns the current program counter (.) to an even
boundary.
Assembler Input
15
1
.file "string"
The .file op creates a symbol table entry where string is the symbol name
and STT_FILE is the symbol table type. string specifies the name of the
source file associated with the object file.
.float val
The .float pseudo op generates an 80387 32 bit floating-point constant
(IEEE 754) into the current section. This is not valid in the .bss section. val
is a floating-point constant. val is a string acceptable to atof(3); that is, an
optional sign followed by a non-empty string of digits with optional
decimal point and optional exponent.
.globl symbol
[, symbol]*
The globl op declares each symbol in the list to be global; that is, each
symbol is either defined externally or defined in the input file and accessible
in other files; default bindings for the symbol are overridden.
A global symbol definition in one file satisfies an undefined reference to the
same global symbol in another file.
Multiple definitions of a defined global symbol is not allowed. If a defined
global symbol has more than one definition, an error occurs.
Note - This pseudo-op by itself does not define the symbol.
.ident “string”
The .ident pseudo op creates an entry in the comment section containing
string. string is any sequence of characters, not including the double
quote (").
.lcomm name, expr
The .lcomm pseudo op allocates storage in the .bss section. The storage is
referenced by the symbol name, and has a size of expr. name cannot be
predefined, and expr must be a positive integer type. If the alignment is
given, the address of name is aligned to a multiple of alignment.
16
x86 Assembly Language Reference Manual—November 1995
1
.local symbol
[, symbol]*
Declares each symbol in the list to be local; that is, each symbol is defined in
the input file and not accessible in other files; default bindings for the
symbol are overridden. These symbols take precedence over weak and global
symbols.
Because local symbols are not accessible to other files, local symbols of the
same name may exist in multiple files.
Note - This pseudo-op by itself does not define the symbol.
.long val
The .long pseudo op generates a long integer (32-bit, two’s complement
value) into the current section. This pseudo op is not valid for the .bss
section. val is a nonfloating-point constant.
.nonvolatile
Defines the end of a block of instruction. The instructions in the block may
not be permuted. This pseudo-op has no effect if:
The block of instruction has been previously terminated by a Control
Transfer Instruction (CTI) or a label
There is no preceding .volatile pseudo-op
.section section_name [, attributes]
Makes the specified section the current section.
The assembler maintains a section stack which is manipulated by the section
control directives. The current section is the section that is currently on top of
the stack. This pseudo-op changes the top of the section stack.
If section_name does not exist, a new section with the specified name and
attributes is created.
If section_name is a non-reserved section, attributes must be included the first
time it is specified by the .section directive.
.set name, expr
The .set pseudo op sets the value of symbol name to expr. This is
equivalent to an assignment.
Assembler Input
17
1
.string “str”
This pseudo op places the characters in str into the object module at the
current location and terminates the string with a null. The string must be
enclosed in double quotes (""). This pseudo op is not valid for the .bss
section.
.text
The .text pseudo op defines the current section as .text.
.value expr [,expr]
The .value pseudo op is used to generate an initialized word (16-bit, two’s
complement value) into the current section. This pseudo op is not valid in
the .bss section. Each expr must be a 16-bit value.
.version string
The .version pseudo op puts the C compiler version number into the
.comment section.
.volatile
Defines the beginning of a block of instruction. The instructions in the
section may not be changed. The block of instruction should end at a
.nonvolatile pseudo-op and should not contain any Control Transfer
Instructions (CTI) or labels. The volatile block of instructions is terminated
after the last instruction preceding a CTI or label.
.weak symbol
[, symbol]
Declares each symbol in the list to be defined either externally, or in the input
file and accessible to other files; default bindings of the symbol are
overridden by this directive.
A weak symbol definition in one file satisfies an undefined reference to a
global symbol of the same name in another file.
Unresolved weak symbols have a default value of zero; the link editor does
not resolve these symbols.
If a weak symbol has the same name as a defined global symbol, the weak
symbol is ignored and no error results.
Note - This pseudo-op does not itself define the symbol.
18
x86 Assembly Language Reference Manual—November 1995
1
symbol =expr
Assigns the value of expr to symbol.
Symbol Definition Pseudo Operations
.def name
The .def pseudo op starts a symbolic description for symbol name. See
endef. name is a symbol name.
.dim expr [,expr]
The .dim pseudo op is used with the .def pseudo op. If the name of a
.def is an array, the expressions give the dimensions; up to four
dimensions are accepted. The type of each expression should be positive.
.endef
The .endef pseudo op is the ending bracket for a .def.
.file name
The .file pseudo op is the source file name. Only one is allowed per
source file. This must be the first line in an assembly file.
.line expr
The .line pseudo op is used with the .def pseudo op. It defines the
source line number of the definition of symbol name in the .def. expr
should yield a positive value.
.ln line [,addr]
This pseudo op provides the relative source line number to the beginning of
a function. It is used to pass information through to sdb.
.scl expr
The .scl pseudo op is used with the .def pseudo op. Within the .def it
gives name the storage class of expr. The type of expr should be positive.
Assembler Input
19
1
.size expr
The .size pseudo op is used with the .def pseudo op. If the name of a
.def is an object such as a structure or an array, this gives it a total size of
expr. expr must be a positive integer.
.stabs name type 0 desc value
.stabn type 0 desc value
The .stabs and .stabn pseudo ops are debugger directives generated by
the C compiler when the -g option are used. name provides the symbol table
name and type structure. type identifies the type of symbolic information
(i.e., source file, global symbol, or source line). desc specifies the number of
bytes occupied by a variable or type, or the nesting level for a scope symbol.
value specifies an address or an offset.
.tag str
The .tag pseudo op is used in conjunction with a previously defined .def
pseudo op. If the name of a .def is a structure or a union, str should be
the name of that structure or union tag defined in a previous .def-.endef
pair.
.type expr
The .type pseudo op is used within a .def-.endef pair. It gives name
the C compiler type representation expr.
.val expr
The .val pseudo op is used with a .def-.endef pair. It gives name (in
the .def) the value of expr. The type of expr determines the section for
name.
20
x86 Assembly Language Reference Manual—November 1995

 

 

 

 

 

 

 

 

Content      ..      1       2         ..

 

 

///////////////////////////////////////