x86 - 64 ASM Programming Manual
x86 - 64 ASM Programming Manual
Reference Manual
Please
Recycle
Contents
1. The SunOS Assembler for x86 . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2. Assembler Input . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.1 Source Files in Assembly Language Format . . . . . . . . . 4
File Organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Values and Symbol Types . . . . . . . . . . . . . . . . . . . . . . . . 6
Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Expression Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Expression Semantics (Absolute vs. Relocatable). . . . . 10
Machine Instruction Syntax . . . . . . . . . . . . . . . . . . . . . . 11
Instruction Description . . . . . . . . . . . . . . . . . . . . . . . . . . 13
2.2 Pseudo Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
General Pseudo Operations . . . . . . . . . . . . . . . . . . . . . . 17
Symbol Definition Pseudo Operations . . . . . . . . . . . . . 22
iii
3. Instruction-Set Mapping . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25
Notational Conventions. . . . . . . . . . . . . . . . . . . . . . . . . . 25
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.2 Segment Register Instructions . . . . . . . . . . . . . . . . . . . . . 27
Load Full Pointer (lds, les, lfs, lgs, and lss) . . . . . . . . . 27
Pop Stack into Word (pop) . . . . . . . . . . . . . . . . . . . . . . . 27
Push Stack into Word(push) . . . . . . . . . . . . . . . . . . . . . . 27
3.3 I/O Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Input from Port (in, ins). . . . . . . . . . . . . . . . . . . . . . . . . . 28
Output from Port (out, outs) . . . . . . . . . . . . . . . . . . . . . . 28
3.4 Flag Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
Load Flags into AH Register (lahf). . . . . . . . . . . . . . . . . 28
Store AH into Flags (sahf) . . . . . . . . . . . . . . . . . . . . . . . . 28
Pop Stack into Flag (popf) . . . . . . . . . . . . . . . . . . . . . . . 28
Push Stack into Flag (pushf) . . . . . . . . . . . . . . . . . . . . . 28
Complement Carry Flag (cmc) . . . . . . . . . . . . . . . . . . . . 28
Clear Carry Flag (clc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Set Carry Flag (stc) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Clear Interrupt Flag (cli) . . . . . . . . . . . . . . . . . . . . . . . . . 29
Set Interrupt Flag (sti) . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
Clear Direction Flag (cld) . . . . . . . . . . . . . . . . . . . . . . . . 29
Set Direction Flag (std) . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.5 Arithmetic Logical Instructions. . . . . . . . . . . . . . . . . . . . 29
Contents v
Convert Word to Long (cwtl) . . . . . . . . . . . . . . . . . . . . 33
Convert Signed Word to Signed Double Word (cwtd). 33
Convert Signed Long to Signed Double Long (cltd) . . 33
3.8 Decimal Arithmetic Instructions . . . . . . . . . . . . . . . . . . . 33
Decimal Adjust AL after Addition (daa) . . . . . . . . . . . . 33
Decimal Adjust AL after Subtraction (das) . . . . . . . . . . 33
ASCII Adjust after Addition (aaa). . . . . . . . . . . . . . . . . 33
ASCII Adjust after Subtraction (aas) . . . . . . . . . . . . . . . 33
ASCII Adjust AX after Multiply (aam) . . . . . . . . . . . . . 34
ASCII Adjust AX before Division (aad). . . . . . . . . . . . . 34
3.9 Coprocessor Instructions . . . . . . . . . . . . . . . . . . . . . . . . . 34
Wait (wait, fwait) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
3.10 String Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Move Data from String to String (movs, smov) . . . . . . 34
Compare String Operands (cmps, scmp). . . . . . . . . . . . 34
Store String Data (stos, ssto) . . . . . . . . . . . . . . . . . . . . . . 34
The Load String Operand (lods, slod) . . . . . . . . . . . . . . 34
Compare String Data (scas, ssca) . . . . . . . . . . . . . . . . . . 35
Look-Up Translation Table (xlat) . . . . . . . . . . . . . . . . . . 35
Repeat Following String Operation (rep, repnz, repz) 35
3.11 Procedure Call and Return Instructions . . . . . . . . . . . . . 35
Call Procedure (call). . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Return from Procedure (ret) . . . . . . . . . . . . . . . . . . . . . . 35
Long Return (lret) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Contents vii
3.15 Bit Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bit Scan Forward . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bit Scan Reverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bit Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Bit Test And Complement . . . . . . . . . . . . . . . . . . . . . . . . 38
Bit Test And Reset. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Bit Test And Set. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.16 Exchange Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Compare and Exchange [486] . . . . . . . . . . . . . . . . . . . . . 39
3.17 Floating Point Transcendental . . . . . . . . . . . . . . . . . . . . . 39
Floating Point Sine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Floating Point Cosine. . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Floating Point Sine and Cosine. . . . . . . . . . . . . . . . . . . . 39
3.18 Floating Point Constant . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Floating Point Load One . . . . . . . . . . . . . . . . . . . . . . . . . 39
3.19 Processor Control Floating Point. . . . . . . . . . . . . . . . . . . 40
Floating Point Load Control Word . . . . . . . . . . . . . . . . . 40
Floating Point Load Environment . . . . . . . . . . . . . . . . . 40
3.20 Other Floating Point . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
Floating Point Different Reminder . . . . . . . . . . . . . . . . . 40
3.21 Floating Point Comparison . . . . . . . . . . . . . . . . . . . . . . . 40
Floating Point Unsigned Compare. . . . . . . . . . . . . . . . . 40
Floating Point Unsigned Compare And Pop . . . . . . . . 40
Floating Point Unsigned Compare And Pop Two . . . . 40
Contents ix
3.28 Miscellaneous Instructions. . . . . . . . . . . . . . . . . . . . . . . . 43
Write Back and Invalidate Cache [486 only] . . . . . . . . . 43
Invalidate [486 only] . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
Invalidate Page [486 only] . . . . . . . . . . . . . . . . . . . . . . . . 43
LOCK Prefix (lock) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
No Operation (nop) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Halt (hlt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.29 Real Transfers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Load real . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Store real . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Store real and pop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
Exchange registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 44
3.30 Integer Transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Integer load . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Integer store . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Integer store and pop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.31 Packed Decimal Transfers . . . . . . . . . . . . . . . . . . . . . . . . 45
Packed decimal (BCD) load. . . . . . . . . . . . . . . . . . . . . . . 45
Packed decimal (BCD) store and pop . . . . . . . . . . . . . . 45
3.32 Additions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Real add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Real add and pop . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
Integer add . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 45
3.33 Subtractions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 46
Contents xi
Absolute value . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Change sign. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
3.38 Comparison Instructions . . . . . . . . . . . . . . . . . . . . . . . . . 49
Compare real. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Compare real and pop . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Compare real and pop twice . . . . . . . . . . . . . . . . . . . . . . 49
Integer compare . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Integer compare and pop . . . . . . . . . . . . . . . . . . . . . . . . 49
Test . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Examine . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.39 Transcendental Instructions . . . . . . . . . . . . . . . . . . . . . . . 50
Partial tangent. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Partial arctangent . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
2x - 1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Y * log2 X . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Y * log2 (X+1) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
3.40 Constant Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Load log2 E . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Load log2 10. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Load log10 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Load loge 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Load pi . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Load + 0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
3.41 Processor Control Instructions . . . . . . . . . . . . . . . . . . . . 51
Contents xiii
A.2 Assembler Command Line Options . . . . . . . . . . . . . . . . 68
A.3 Disassembling Object Code . . . . . . . . . . . . . . . . . . . . . . . 69
Index.......................................................................................... 71
Table 2-3 8-Bit (byte), 16-Bit (word), and 32-Bit (long) General Registers 12
xv
xvi x86 Assembly Language Reference Manual—August 1994
The SunOS Assembler for x86 1
This section contains a brief description of the SunOS assembler that runs on
x86 and 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.
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.
Further more, the assembler responds to directives that allow the programmer
a great deal of direct control over the contents of the relocatable object file into
which it translates the input source files.
1
1
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.
1.1 References
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
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.
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.
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.
3
2
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.
File Organization
The 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 semi-colon (;) 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.
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.
Assembler Input 5
2
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.
.bss This symbol is of type bss. It is used to label the beginning of a .bss
section in the program being assembled.
Symbol Types
Symbol type is one of the following:
undefined
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.
Section Purpose
bss This is an initialized section. Space is not allocated for this seg-
ment in the object file.
Assembler Input 7
2
An optional section, .comment, may also be produced (see Chapter 4, 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 2-1 Operators Supported by the Assembler
Operator Action
+ Addition
− Subtraction
\* Multiplication
\/ Division
& Bit-wise logical and
| Bit-wise logical or
>> Right shift
<< Left shift
\% Remainder operator
! Bit-wise logical and not
Expression Syntax
In the following table that includes 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.
term : id
| number
| "-" term
| "[" expr "]"
| "<o>" term
| "<s>" term
;
id : LABEL
;
number : DEC_VAL
| HEX_VAL
| OCT_VAL
| BIN_VAL
;
Assembler Input 9
2
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 last example, you must declare the relocatable expressions before taking
their difference.
The following list delineates 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 system’s 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, whereas 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 the “Notational
Conventions” section. 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.
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 listed also.
Assembler Input 11
2
Table 2-3 8-Bit (byte), 16-Bit (word), and 32-Bit (long) General Registers
8-Bit (byte) General Registers
Instruction Description
This section describes the SunOS x86 instruction syntax.
Assembler Input 13
2
Notational Conventions
This manual uses the following notational conventions:
• The mnemonics are expressed in a regular expression-type syntax.
° Alternatives separated by a vertical bar (|) and enclosed within square
brackets ([]) denote that you must choose one of them.
° Alternatives enclosed within curly braces ({}) denote that you can use
one or none of them.
° The vertical bar separates different suffixes for operators or operands. For
example, imm[8|16|32] indicates that an 8-, 16-, or 32-bit immediate
value is permitted in an instruction.
• imm[8|16|32|48] — an immediate value. You define immediate values
using the regular expression syntax previously described. If there is a choice
between operand sizes, the assembler will choose the smallest
representation.
• reg[8|16|32] — a general-purpose register, where each number indicates
one of the following:
Assembler Input 15
2
• disp[8|32] — the number of bits used to define the distance of a relative
jump; because the assembler only supports a 32-bit address space, only 8-bit
sign extended and 32-bit addresses are supported.
• immPtr — an immediate pointer; when the immediate form of a long call or
a long jump is used, the selector and offset are encoded as an immediate
pointer. An immediate pointer consists of $imm16, $imm32 where the first
immediate value represents the segment and the second represents the
offset.
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.
Assembler Input 17
2
.align val
The align pseudo op causes the next data generated to be aligned modulo
val. val should be a positive integer value.
.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
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.
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.
.data
.double val
The .even pseudo op aligns the current program counter (.) to an even
boundary.
.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 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 will satisfy 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 will occur.
.ident “string”
Assembler Input 19
2
.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 will be aligned to a multiple of alignment.
.long val
.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
The .set pseudo op sets the value of symbol name to expr. This is equivalent
to an assignment.
.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
.version string
The .version pseudo op puts the C compiler version number into the
.comment section.
.volatile
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 will satisfy 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.
Assembler Input 21
2
• If a weak symbol has the same name as a defined global symbol, the weak
symbol is ignored and no error results.
symbol =expr
.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.
.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.
.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.
Assembler Input 23
2
3.1 Introduction
This chapter describes the instruction set mappings for the SunOS x86
processor. For more details of the operation and a summary of the exceptions,
please refer to the i486 Microprocessor Programmer’s Reference Manual from Intel
Corporation.
Notational Conventions
The notational conventions used in the instructions included in this chapter are
described below:
• The mnemonics are expressed in a regular expression-type syntax.
• When a group of letters is separated from other letters by a bar (|) within
square brackets or curly braces, then the group of letters between the bars or
between a bar and a closing bracket or brace is considered an atomic unit.
For example, fld[lst] means fldl, flds, or fldt; fst{ls} means fst,
fstl, or fsts; and fild{l|ll} means fild, fildl, or fildll.
•
° Square brackets ([]) denotes choices, but at least one irequired.
25
3
° Alternatives enclosed within curly braces ({}) denote that you can use
one or none of them
° The vertical bar separates different suffixes for operators or operands. For
example, the following indicates that an 8-, 16-, or 32-bit immediate value
is permitted in an instruction:
imm[8|16|32]
• The SunOS operators are built from the Intel operators by adding suffixes to
them. The 80387, 80486 deals with three data types: integer, packed decimal,
and real.
The SunOS assembler is not typed; the operator has to carry with it the type
of data item it is operating on. If the operation is on an integer, the following
suffixes apply: none for Intel’s short(16 bits), l for Intel’s long (32 bits),
and ll for Intel’s longlong(64 bits). If the operator applies to reals, then: s
is short (32 bits), l is long (64 bits), and t is temporary real(80 bits).
• reg[8|16|32] defines a general-purpose register, where each number
indicates one of the following:
References
This document presumes that you are familiar with the manner in which the
Intel instruction sets function. For more information on specific instruction
descriptions, please refer to x86 product documentation from Intel
Corporation.
Instruction-Set Mapping 27
3
Instruction-Set Mapping 29
3
Increment by 1 (inc)
inc{bwl} r/m[8|16|32]
Decrease by 1 (dec)
dec{bwl} r/m[8|16|32]
Instruction-Set Mapping 31
3
or{bwl} imm[8|16|32], r/m[8|16|32]
Instruction-Set Mapping 33
3
Instruction-Set Mapping 35
3
Instruction-Set Mapping 37
3
Bit Test
bt{wl} imm8, r/m[16|32]
bt{wl} reg[16|32], r/m[16|32]
Instruction-Set Mapping 39
3
fldpi
fldlg2
fldln2
fldz
Move
mov{bwl} imm[8|16|32], r/m[8|16|32]
mov{bwl} reg[8|16|32], r/m[8|16|32]
mov{bwl} r/m[8|16|32], reg[8|16|32]
Instruction-Set Mapping 41
3
Rotate Left
rol{bwl} imm8, r/m[8|16|32]
rol{bwl} %cl, r/m[8|16|32]
Rotate Right
ror{bwl} imm8, r/m[8|16|32]
Instruction-Set Mapping 43
3
No Operation (nop)
nop
Halt (hlt)
hlt
Address Prefix
addr16
Data Prefix
data16
Load real
fld{lst}
Store real
fst{ls}
Exchange registers
fxch
Integer load
fild{l|ll}
Integer store
fist{l}
3.32 Additions
Real add
fadd{ls}
Integer add
fiadd{l}
Instruction-Set Mapping 45
3
3.33 Subtractions
Subtract real
subp
Integer subtract
fsubrp
3.34 Multiplications
Multiply real
fmul{ls}
Integer multiply
fimul{l}
3.35 Divisions
Divide real
fdiv{ls}
Integer divide
fidiv{l}
Instruction-Set Mapping 47
3
Replace the following instructions, in column 1, with their substitutions, in
column 2, for x86 platforms:
Square root
fsqrt
Scale
fscale
Partial remainder
fprem
Round to integer
frndint
Absolute value
fabs
Change sign
fchs
Compare real
fcom{ls}
Integer compare
ficom{l}
Test
ftst
Instruction-Set Mapping 49
3
Examine
fxam
Partial tangent
fptan
Partial arctangent
fptan
2x - 1
f2xm1
Y * log2 X
fyl2x
Y * log2 (X+1)
fyl2xp1
Load log2 E
fldl2e
Load log2 10
fldl2t
Load log10 2
fldlg2
Load loge 2
fldln2
Load pi
fldpi
Load + 0
fldz
Initialize processor
finit/fninit
No operation
fnop
Save state
fsave/fnsave
Store environment
fstenv/fnstenv
Instruction-Set Mapping 51
3
Restore state
frstor
CPU wait
fwait/wait
Clear exceptions
fclex/fnclex
Free registers
ffree
The three main kinds of ELF files are relocatable, executable and shared object
files. The assembler may also produce ancillary output incidental to the
translation process. For example, if the assembler is invoked with the -V
option, it may write information to standard output and to standard error.
The assembler also creates a default output file when standard input or
multiple input files are used. Ancillary output has little direct connection to the
translation process, so it is not properly a subject for this manual. Information
about such output appears in as(1) manual page.
53
4
Hence, this chapter presents an overview of ELF for the relocatable object files
produced by the assembler. The fully detailed definition of ELF appears in the
System V Application Binary Interface and the Intel 386 Processor Supplement.
The ELF header is always the first part of an ELF file. It is essentally a structure
of fixed size and format. The fields, or members, of this structure describe the
nature, organization and contents of the rest of the file. In particular, the ELF
header has a field which specifies the location within the file at which the
section header table begins.
The section header table is an array of section headers, which are structures of
fixed size and format. The section headers are thus the elements of the array, or
the entries in the table. The section header table has exactly one entry for each
section in the ELF file. However, the table may also have entries (section
headers) that do not correspond to any section in the file. Such entries and
their array indices are reserved. The members of each section header constitute
information useful to the linker about the contents of the corresponding
section, if any.
All of a relocatable file’s information that does not lie within its ELF header or
its section header table lies within its sections. Sections contain most of the
information needed to combine relocatable files with other ELF files to produce
shared object files or executable files. Sections also contain the material to be
combined. For example, sections may hold:
• Relocation tables
• Symbol tables
• String tables
Each section in an ELF file fills a contiguous (possibly empty) sequence of that
file’s bytes. Sections never overlap. However, the (set theoretic) union of a
relocatable file’s ELF header, the file’s section header table, and all the file’s
ELF Header
The ELF header is always located at the beginning of the ELF file. It describes
the ELF file organization and contains the actual sizes of the object file control
structures.
The ELF header consists of the following fields, or members, some of which
have the value 0 for relocatable files:
e_ident – This is a byte array consisting of the EI_NIDENT initial bytes of the
ELF header, where EI_NIDENT is a name for 16. The elements of this array
mark the file as an ELF object file and provide machine-independent data
which may be used to decode and interpret the file’s contents.
e_type – Identifies the object file type. A value of 1, which has the name
ET_REL, specifies a relocatable file. Table 4-1 describes all the object file
types.
e_version – Identifies the version of this object file’s format. This field should
have the current version number, named EV_CURRENT.
e_phoff – Program header table’s file offset, in bytes. The value of 0 indicates
no program header. (Relocatable files do not need a program header table.)
e_shoff – Section header table’s file offset, in bytes. The value of 0 indicates
no section header table. (Relocatable files must have a section header table.)
e_flag – Processor-specific flags associated with the file. For the Intel 80386,
this field has value 0.
Assembler Output 55
4
e_phentsize – Size, in bytes, of entries in the program header table. All entries
are the same size. (Relocatable files do not need a program header table.)
e_shstrndx – Section header table index of the entry associated with the
section name string table. A value of SHN_UNDEF indicates the file does
not have a section name string table.
Section Header
The section header table has all of the information necessary to locate and isolate
each of the file’s sections. A section header entry in a section header table
contains information characterizing the contents of the corresponding section,
if the file has such a section.
sh_name – Specifies the section name. The value of this field is an index into
the section header string table section, wherein it indicates the beginning of
a null-terminated string that names the section.
sh_addr – Address at which the first byte resides if the section appears in the
memory image of a process; a value of 0 indicates the section will not
appear in the memory image of a process.
sh_offset – Specifies the byte offset from the beginning of the file to the first
byte in the section.
Assembler Output 57
4
For example, if a section contains a long (32 bits), the entire section must be
ensured long alignment, so sh_addralign would have the value 4. Only 0
and positive integral powers of 2 are currently allowed as values for this
field. A value of 0 or 1 indicates no address alignment constraints.
Interpretation by
Name Value Description sh_info sh_link
Interpretation by
Name Value Description sh_info sh_link
SHT_SYMTAB 2 Is a complete symbol table, usually One greater than the The section
for link editing. This table may also symbol table index of header index of
be used for dynamic linking; the last local symbol. the associated
however, it may contain many string table.
unnecessary symbols.
Note: Only one section of this type is
allowed in a file
SHT_RELA 4 Contains relocation entries with The section header The section
explicit addends. A file may have index of the section to header index of
multiple relocation sections. which the relocation the associated
applies. symbol table.
Assembler Output 59
4
Table 4-3 Section Types (Continued)
Interpretation by
Name Value Description sh_info sh_link
SHT_REL 9 Contains relocation entries without The section header The section
explicit addends. A file may have index of the section to header index of
multiple relocation sections. which the relocation the associated
applies. symbol table.
SHT_DYNSYM 11 Is a symbol table with a minimal set One greater than the The section
of symbols for dynamic linking. symbol table index of header index of
Note: Only one section of this type is the last local symbol. the associated
allowed in a file string table.
Note – Some section header table indices are reserved, and the object file will
not contain sections for these special indices.
Sections
A section is the smallest unit of an object file that can be relocated. Sections
containing the following material usually appear in relocatable ELF files:
• Executable text
• Read-only data
• Read-write data
• Read-write uninitialized data (only section header appears)
Sections do not need to occur in any particular order within the object file. The
sections of a relocatable ELF file contain all of that file’s information which is
not contained in the ELF header or in the section header table. The sections in
any ELF file must satisfy several conditions:
1. Every section in the file must have exactly one section header entry in the
section header table to describe the section. However, the section header
table may have section header entries which correspond to no section in the
file.
2. Each section occupies one contiguous sequence of bytes within a file. The
section may be empty (even so, its section header entry in the section header
table may have a non-zero value for the field sh_size).
3. A byte in a file can reside in at most one section. Sections in a file cannot
overlap.
4. An object file may have inactive space, which is the set of all bytes in the file
which are not part of the ELF header, or of the section header table, or of the
program header table (for executable files), or of any section in the file. The
contents of the inactive space are unspecified.
Sections can be added for multiple text or data segments, shared data, user-
defined sections, or information in the object file for debugging.
Assembler Output 61
4
Note – Not all of the sections for which there are entries in the file‘s section
header table need to be present.
Predefined Sections
Sections having certain names beginning with "." (dot) are predefined, with
their types and attributes already assigned. These special sections are of two
kinds: predefined user sections and predefined non-user sections.
Relocation Tables
Locations represent addresses in memory if a section is allocatable; that is, its
contents are to be placed in memory at program runtime. Symbolic references
to these locations must be changed to addresses by the link editor.
Assembler Output 63
4
The assembler produces a companion relocation table for each relocatable
section. The table contains a list of relocations (that is, adjustments to locations
in the section) to be performed by the link editor.
Symbol Tables
The symbol table contains information to locate and relocate symbolic
definitions and references. The assembler creates the symbol table section for
the object file. It makes an entry in the symbol table for each symbol that is
defined or referenced in the input file and is needed during linking.
The symbol table is then used by the link editor during relocation. The symbol
table’s section header contains the symbol table index for the first non-local
symbol.
st_name – Index into the object file’s symbol string table. A value of zero
indicates the corresponding entry in the symbol table has no name;
otherwise, the value represents the string table index that gives the symbol
name.
st_size – Size of symbol. A value of 0 indicates that the symbol has either no
size or an unknown size.
st_info – Specifies the symbol type and binding attributes. Table 4-6 and
Table 4-7 describe the symbol types and binding attributes.
3 section Symbol is associated with a section. These types of symbols are primarily
used for relocation.
4 file Gives the name of the source file associated with the object file.
0 local Symbol is defined in the object file and not accessible in other files. Local
symbols of the same name may exist in multiple files.
1 global Symbol is either defined externally or defined in the object file and
accessible in other files.
2 weak Symbol is either defined externally or defined in the object file and
accessible in other files; however, these definitions have a lower
precedence than globally defined symbols.
Assembler Output 65
4
String Tables
A string table is a section which contains null-terminated variable-length
character sequences, or strings. The object file uses these strings to represent
symbol names and file names. The strings are referenced by indices into the
string table section. The first and last bytes of a string table must be the null
character.
• A string table index may refer to any byte in the section.
• Empty string table sections are permitted if zero is the value of sh_size in
the section header entry for the string table in the section header table.
A string may appear multiple times and may also be referenced multiple times.
References to substrings may exist, and unreferenced strings are allowed.
Note – The language drivers (such as cc and f77) invoke the assembler
command line with the fbe command. You can use either the as or fbe
command to invoke the assembler command line.
The as command translates the assembly language source files, inputfile, into
an executable object file, objfile. The Intel assembler recognizes the file name
argument hyphen (-) as the standard input. It accepts more than one file name
on the command line. The input file is the concatenation of all the specified
files. If an invalid option is given or the command line contains a syntax error,
the Intel assembler prints the error (including a synopsis of the command line
syntax and options) to standard error output, and then terminates.
The Intel assembler supports #define macros, #include files, and symbolic
substitution through use of the C preprocessor cpp. The assembler invokes the
preprocessor before assembly begins if it has been specified from the command
line as an option. (See the -P option.)
67
A
-Dname
-Dname=def
When the -P option is in effect, these options are passed to the cpp
preprocessor without interpretation by the as command; otherwise, they are
ignored.
-Ipath
When the -P option is in effect, this option is passed to the cpp
preprocessor without interpretation by the as command; otherwise, it is
ignored.
-m
This new option runs m4 macro preprocessing on input. The m4
preprocessor is more powerful than the C preprocessor (invoked by the -P
option), so it is more useful for complex preprocessing. See the SunOS 5.1
Reference Manual for x86 for a detailed description of the m4 macro-processor.
-o outfile
Takes the next argument as the name of the output file to be produced. By
default, the .s suffix, if present, is removed from the input file and the .o
suffix is appended to form the output file name.
-P
Run cpp, the C preprocessor, on the files being assembled. The preprocessor
is run separately on each input file, not on their concatenation. The
preprocessor output is passed to the assembler.
-Q[y|n]
This new option produces the “assembler version” information in the
comment section of the output object file if the y option is specified; if the n
option is specified, the information is suppressed.
-s
This new option places all stabs in the .stabs section. By default, stabs are
placed in stabs.excl sections, which are stripped out by the static linker
ld during final execution. When the -s option is used, stabs remain in the
final executable because .stab sections are not stripped out by the static
linker ld.
-Uname
When the -P option is in effect, this option is passed to the cpp
preprocessor without interpretation by the as command; otherwise, it is
ignored.
-V
This option writes the version information on the standard error output.
71
D P
-D option, 68 -P option, 68
default output file, 53 predefined non-user sections, 63
dis program, 69 predefined user sections, 62
disassembling object code, 69 Programming Utilities - SunOS 5.0, 2
pseudo-operations, 17
F
f77 language driver, 67 Q
fbe command, 67 -Q option, 68
.file, 19
R
G references
.globl, 19 other, 2
relocatable files, 53
H relocation tables, 63
hyphen (-), 67
S
I -s option, 69
.section, 20
-I option, 68
section header, 56
invoking, as command, 67
sections, 61
string tables, 66
L strings
language drivers, 67 multiple references in string table, 66
.local, 20 unreferenced in string table, 66
strings, multiple in string table, 66
M sub-strings in string table
references to, 66
-m option, 68
symbol, 22
multiple files, on as command line, 67
symbol tables, 64
multiple sections, 61
multiple strings, in string table, 66
T
The, 1
N
.nonvolatile, 20
U
-U option, 69
O
-o option, 68
W
.weak, 21
73
74 x86 Assembly Language Reference Manual—August 1994