|
|
coherent
as Command as
i8086 assembler
aass [-ggllxx] [ -oo_f_i_l_e ] _f_i_l_e ...
as is the Mark Williams assembler. It is a multipass assembler
that turns files of assembly language into relocatable object
modules similar to those produced by the compiler. as is
designed for writing small assembly-language subroutines.
Because it is not intended to be used for full-scale assembly-
language programming, it lacks many of the more elaborate
facilities of full-fledged assemblers. For example, there are no
facilities for conditional compilation or user-defined macros.
However, it does optimize span-dependent instructions (for ex-
ample, branches).
***** Features *****
as includes the following features:
* It automatically compiles jump instructions into either
regular (three-byte) jumps or short (two-byte) jumps,
whichever is required. There is no explicit short jump in-
struction.
* The assembler supports temporary labels, which conserves sym-
bol table space and relieves the you of having to invent many
unique labels.
* Program modules are relocatable. They can be linked with each
other and with C program modules produced by the COHERENT com-
piler. All assembled modules must be linked before they can
be executed.
* The assembler does not support file inclusion, but multiple
source files can be concatenated and assembled by including
their names in the command line to run the assembler.
* The assembler generates SMALL model objects in the COHERENT
l.out object format.
***** Usage *****
Normally, the assembler is invoked via the cccc command, which will
automatically assemble and link any file of source code that has
the suffix .ss. If you wish, however, you can invoke the as-
sembler as a separate program, by using the following command
line:
aass [-ggllxx] [ -oo _f_i_l_e ] _f_i_l_e ...
The named _f_i_l_es are concatenated and the resulting object code is
written to the file specified by the -o option, or to file l.out
COHERENT Lexicon Page 1
as Command as
if no -o option is given.
The option -g causes all symbols that are undefined at the end of
the first pass to be given the type undefined external, as though
they had been declared with a .globl directive.
The option -l tells the assembler to generate a listing. It
writes the listing to the standard output, normally the terminal;
it may be easily redirected to a file or printer using the >
operator.
The option -x strips from the symbol table of the object module
all non-global symbols that begin with the character `L'. This
speeds up the loading of files by removing compiler-generated
labels from the symbol table.
***** Register Names *****
The following lists the identifiers that represent the i8086
machine registers, which are predefined:
AX SP AL AH CS
BX BP BL BH DS
CX SI CL CH ES
DX DI DL DH SS
***** Lexical Conventions *****
Assembler tokens consist of identifiers (also known as ``sym-
bols'' or ``names''), constants, and operators.
An identifier is a sequence of alphanumeric characters (including
the period `.' and the underscore `_'). The first character must
not be numeric. Only the first 16 characters of the name are
significant; it throws away the remainder. Upper case and lower
case are different. The machine instructions, assembly direc-
tives, and built-in symbols that are used frequently are in lower
case.
Numeric constants are defined by the assembler by using the same
syntax as the C compiler: a sequence of digits that begins with a
zero `0' is an octal constant; a sequence of digits with a
leading `0x' is a hexadecimal constant (`A' through `F' have the
decimal values 10 through 15); and any strings of digits that do
not begin with `0' are interpreted as decimal constants.
A character constant consists of an apostrophe followed by an
ASCII character. The constant's value is the ASCII code for the
character, right-justified in the machine word. For example, an
instruction to move the letter `A' to the register al could be
expressed in either of two equivalent ways:
COHERENT Lexicon Page 2
as Command as
mov al,$0x41
mov al,$'A
The dollar sign indicates an immediate operand.
A blank space can be represented either 00xx2200 (its ASCII value in
hexadecimal), or as an apostrophe followed by a space (' ), which
on paper looks like just an apostrophe alone.
The following gives the multi-character escape sequences that can
be used in a character constant to represent special characters:
\bb Backspace (0010)
\ff Formfeed (0014)
\nn Newline (0012)
\rr Carriage return(0015)
\tt Tab (0011)
\vv Vertical tab (0013)
\_n_n_n Octal value (0_n_n_n)
A blank space can be represented either as 0x20 (its ASCII value
in hexadecimal), or as an apostrophe followed by a space (' ),
which on the page would look like just an apostrophe.
***** Blanks and Tabs *****
Blanks and tab characters may be used freely between tokens, but
not within identifiers. A blank or a tabulation character is
required to separate adjacent tokens not otherwise separated,
e.g., between an instruction opcode and its first operand.
***** Comments *****
Comments are introduced by a slash (`/') and continue until the
end of the line. All characters in comments are ignored by the
assembler.
***** Program Sections *****
The assembler permits you to divide programs into sections, each
corresponding (roughly) to a functional area of the address
space. Each program section has its own location counter during
assembly. There are eight program sections, subdivided into
three groups containing code, data and tables:
code: sshhrrii Shared instruction
bbssssii Uninitialized instruction
pprrvvii Private instruction
data: pprrvvdd Private data
sshhrrdd Shared data
COHERENT Lexicon Page 3
as Command as
bbssssdd Uninitialized data
ssttrrnn Strings
tables: ssyymmtt Symbol table
All Mark Williams assemblers use the same set of sections. This
increases the portability of programs between operating systems.
Not all the sections are distinct under COHERENT, however; the
meanings of the sections under (including hints as to how the C
compiler uses them) are as follows:
shri (shared instruction) is the same as prvi (private instruc-
tion); the adjective shared refers to the sharing of physical
memory between two or more concurrent processes. prvi is used
for all code generated by the C compiler.
Similarly, there is no distinction between shrd and prvd. The
compiler uses the latter for all external and static data that
are explicitly initialized in a C program.
Uninitialized sections are actually initialized to zeros. The
reason is that the C compiler uses the bssd (uninitialized data)
section for external or static data that are not explicitly in-
itialized: the C language guarantees that these data are in fact
initialized to zeros. The bssi (uninitialized instruction) sec-
tion is not used by the compiler.
The strn (strings) section is actually a special part of the data
section, used by the C compiler to store string constants. It is
synonymous with prvd under COHERENT.
The symt (symbol table) section contains the symbol table used by
the linker. Both the C compiler and the assembler generate sym-
bol tables that go in this section.
In most cases, you need not worry about what all these program
sections are, and can simply write code under the keyword .prvi
or .shri, and write data under the keyword .prvd or .shrd. You
are advised not to place items in the symt section, as this sec-
tion is used for internal communication among the C compiler, the
assembler, and the linker.
At the end of assembly, the sections of a program are con-
catenated so that in the assembly listing the program looks like
a monolithic block of code and data. All ccooddee sections are com-
bined into the i8086 ccooddee segment, and all ddaattaa sections into the
i8086 ddaattaa segment. The symbol table is not linked when the
program is executed, and so is not assigned to any i8086 segment.
***** The Current Location *****
The special symbol `.' (period) is a counter that represents the
current location. The current location can be changed by an as-
signment; for example:
COHERENT Lexicon Page 4
as Command as
. = .+START
The assignment must not cause the value to decrease, and it must
not change the program section, i.e., the right-hand operand must
be defined in the same section as the current section.
***** Expressions *****
An expression is a sequence of symbols representing a value and a
program section. Expressions are made up of identifiers, con-
stants, operators, and brackets. All binary operators have equal
precedence and are executed in a strict left-to-right order (un-
less altered by brackets).
Notice that square brackets, `[' and `]', group expression
elements, because parentheses are used for indexed register ad-
dressing.
***** Types *****
Every expression has a type determined by its operands. The
simplest operands are symbols. The types of symbols are as
follows:
Undefined A symbol is defined if it is a constant or a label, or
when assigned a defined value; otherwise, it is un-
defined. A symbol may become undefined if it is as-
signed the value of an undefined expression. It is an
error to assemble an undefined expression in pass 2.
Pass 1 allows assembly of undefined expressions, but
phase errors may be produced if undefined expressions
are used in certain contexts, such as in a .blkw or
.blkb.
Absolute An absolute symbol is one defined ultimately from a
constant or from the difference of two relocatable
values.
Register These are the machine registers.
Relocatable
All other user symbols are relocatable symbols in some
program section. Each program section is a different
relocatable type.
Each keyword in the assembler has a secret type that identifies
it internally; however, all of these secret types are converted
to absolute in expressions. Thus, any keyword may be used in an
expression to obtain the basic value of the keyword. This is
useful when employing the keywords that define machine instruc-
tions. The basic value of a machine operation is usually the op-
code with any operand-specific bits set to zero.
COHERENT Lexicon Page 5
as Command as
Notice that the type of an expression does not include such at-
tributes as length (word or byte), so the assembler will not
remember whether you defined a particular variable to be a word
or a byte. Addresses and constants have different types, but the
assembler does not treat a constant as an immediate value unless
it is preceded by a dollar sign `$'. If you use a constant where
an address is expected, aass will treat the constant like an ad-
dress (and vice versa). It is up to you to distinguish between
variables and addresses or immediate values.
***** Operators *****
The following figure shows various characters interpreted as
operators in expressions.
+ Addition
- Subtraction
* Multiplication
- Unary negation
~ Unary complement
^ Type transfer
| Segment construction
You can group expressions by means of square brackets (`[' and
`]'); parentheses are reserved for use in address mode descrip-
tions.
***** Type Propagation *****
When operands are combined in expressions, the resulting type is
a function of both the operator and the types of the operands.
The operators `*', `~', and unary `-' can only manipulate ab-
solute operands and always yield an absolute result.
The operator `+' signifies the addition of two absolute operands
to yield an absolute result, and the addition of an absolute to a
relocatable operand to yield a result with the same type as the
relocatable operand.
The binary operator `-' allows two operands of the same type, in-
cluding relocatable, to be subtracted to yield an absolute
result. It also allows an absolute to be subtracted from a
relocatable, to yield a result with the same type as the relocat-
able operand.
The binary operator `^' yields a result with the value of its
left operand and the type of its right operand. It may be used
to create expressions (usually intended to be used in an assign-
ment statement) with any desired type.
***** Statements *****
A program consists of a sequence of statements separated by
COHERENT Lexicon Page 6
as Command as
newlines or by semicolons. There are four kinds of statements:
null statements, assignment statements, keyword statements, and
machine instructions.
***** Labels *****
You can precede any statement by any number of labels. There are
two kinds of labels: _n_a_m_e _l_a_b_e_l_s and _t_e_m_p_o_r_a_r_y _l_a_b_e_l_s.
A name label consists of an identifier followed by a colon (:).
The program section and value of the label are set to that of the
current location counter. It is an error for the value of a
label to change during an assembly. This most often happens when
an undefined symbol is used to control a location counter adjust-
ment.
A temporary label consists of a digit (00 to 99) followed by a
colon (:). Such a label defines temporary symbols of the form
xxff and xxbb, where xx is the digit of the label. References of the
form xxff refer to the first temporary label xx: forward from the
reference; those of the form xxbb refer to the first temporary
label xx: backward from the reference. Such labels conserve sym-
bol table space in the assembler.
***** Null Statements *****
A null statement is an empty line, or a line containing only
labels or a comment. Null statements can occur anywhere. They
are ignored by the assembler, except that any labels are given
the current value of the location counter.
***** Assignment Statements *****
An assignment statement consists of an identifier followed by an
equal sign `=' and an expression. The value and program section
of the identifier are set to that of the expression. Any symbol
defined by an assignment statement may be redefined, either by
another assignment statement or by a label. An assignment
statement is equivalent to the equ keyword statement found in
many assemblers.
***** Assembler Directives *****
Assembler directives give instructions to the assembler. Each
directive keyword begins with a period, and in general they are
followed by operands.
The following directives change the current program section to
the named section:
COHERENT Lexicon Page 7
as Command as
.bssd
.bssi
.prvd
.prvi
.shrd
.shri
.strn
.symt
The current location counter is set to the highest previous value
of the location counter for the selected section.
The following describes the directives in detail.
.aasscciiii _s_t_r_i_n_g
The first non-white space character, typically a quotation
mark, after the keyword is taken as a delimiter. as as-
sembles successive characters from the string into succes-
sive bytes until it encounters the next instance of this
delimiter. To include a quotation mark in a string, use
some other character for the delimiter.
It is an error for a newline to be encountered before
reaching the final delimiter. You can use a multi-character
constant in the string to represent newlines and other
special characters.
.bbllkkbb _e_x_p_r_e_s_s_i_o_n
Assemble a block of bytes that are filled with zeroes. The
block is expression bytes long.
.bbllkkww _e_x_p_r_e_s_s_i_o_n
Assemble a block of words that are filled with zeroes. The
block is expression words long.
.bbyyttee _e_x_p_r_e_s_s_i_o_n [, _e_x_p_r_e_s_s_i_o_n ]
The _e_x_p_r_e_s_s_i_o_ns in the list are truncated to byte size and
assembled into successive bytes. Expressions in the list
are separated by commas.
.eevveenn
Force alignment by inserting a null byte of data, if neces-
sary, to set the location counter to the next even location.
.oodddd
Force alignment by inserting a null byte of data, if neces-
sary, to set the location counter to the next odd location.
.gglloobbll _i_d_e_n_t_i_f_i_e_r [, _i_d_e_n_t_i_f_i_e_r ]
The identifiers in the comma-separated list are marked as
global. If they are defined in the current assembly, they
may be referenced by other object modules; if they are un-
defined, they must be resolved by the linker before execu-
tion.
COHERENT Lexicon Page 8
as Command as
.ppaaggee
Force the printed listing of your assembly-language program
to skip to the top of a new page by inserting a form-feed
character into the file. The title is printed at the top of
the page.
.ttiittllee _s_t_r_i_n_g
Print string at the top of every page in the listing. This
directive also causes the listing to skip to a new page.
.wwoorrdd _e_x_p_r_e_s_s_i_o_n [, _e_x_p_r_e_s_s_i_o_n ]
Truncate _e_x_p_r_e_s_s_i_o_ns to word length and assemble the resul-
ting data into successive words. Expressions in the list
are separated by commas.
***** Address Descriptors *****
The following syntax is used for general source and destination
address descriptors. The symbol `r' refers to a register and the
symbol `e' to an expression. Please refer to the following
figure.
_S_y_n_t_a_x _A_d_d_r_e_s_s_i_n_g _M_o_d_e _E_x_a_m_p_l_e
r Register mov ax, cx
e Direct address mov ax, 0800
(r) Indexing, no displacement movax, (bx)
e(r) Indexing with displacement movax, 2(bx)
(r,r) Double indexing, no displacementmov ax, (bx, si)
e(r,r) Double indexing with displacementmov ax, 2(bx, si)
$e Immediate mov ax, $0800
Note that the dollar sign is always used to indicate an immediate
value, even if the expression is a constant.
A direct address is interpreted as either a direct address or a
PC-relative displacement, depending on the requirements of the
instruction.
If an address descriptor indicates an indexing mode and the base
expression is of type absolute, the assembler uses the shortest
displacement length (zero, one, or two bytes) that can hold the
expression's value. Relocatable base expressions, whose values
cannot be completely determined until the program is loaded, are
always assigned two-byte displacements.
Any address descriptor may be modified by a segment escape
prefix. A segment escape prefix consists of a segment register
name followed by a colon `:'. The escape causes the assembler to
produce a segment override prefix that uses the specified segment
register as an operand. The assembler does not produce segment
override prefixes unless explicitly required by an instruction.
COHERENT Lexicon Page 9
as Command as
***** 8086 Instructions *****
The following machine instructions are defined. The examples
illustrate the general syntax of the operands. Combinations that
are syntactically valid may be forbidden for semantic reasons.
The examples use the following references:
_a General address
_a_l AL register
_a_x AX register
_c_l CL register
_d Direct address
_d_x DX register
_e Expression
$_e Immediate expression
_m Memory address (not an immediate)
_p Port address
aass treats as ordinary one-byte machine operations some operations
that the Intel assembler ASM86 handles with special syntax; these
include the _l_o_c_k and _r_e_p_e_a_t prefixes. aass makes no attempt to
prevent the generation of incorrect sequences of these prefix
bytes.
Although every machine operation has a type and value associated
with it, in most cases the value was chosen to help aass format the
machine instructions.
For more information on these instructions, see the Intel ASM86
Assembly Language Reference Manual.
aaaaaa ASCII adjust AL after addition
aaaadd ASCII adjust AX before division
aaaamm ASCII adjust AX after multiply
aaaass ASCII adjust AL after subtraction
aaddccbb _r, _a Add with carry, byte
aaddcc _r, _a Add with carry, word
aaddccbb _a, _r Add with carry, byte
aaddcc _a, _r Add with carry, word
aaddccbb _a, $_e Add with carry, byte
aaddcc _a, $_e Add with carry, word
aaddddbb _r, _a Add, byte
aadddd _r, _a Add, word
aaddddbb _a, _r Add, byte
aadddd _a, _r Add, word
aaddddbb _a, $_e Add, byte
aadddd _a, $_e Add, word
aannddbb _r, _a Logical and, byte
aanndd _r, _a Logical and, word
aannddbb _a, _r Logical and, byte
aanndd _a, _r Logical and, word
COHERENT Lexicon Page 10
as Command as
aannddbb _a, $_e Logical and, byte
aanndd _a, $_e Logical and, word
ccaallll _d Near call, PC-relative
ccbbww Convert byte into word
ccllcc Clear carry flag
cclldd Clear direction flag
ccllii Clear interrupt flag
ccmmcc Complement carry flag
ccmmppbb _r, _a Compare two operands, byte
ccmmpp _r, _a Compare two operands, word
ccmmppbb _a, _r Compare two operands, byte
ccmmpp _a, _r Compare two operands, word
ccmmppbb _a, $_e Compare two operands, byte
ccmmpp _a, $_e Compare two operands, word
ccmmppss Compare string operands, bytes
ccmmppssbb Compare string operands, bytes
ccmmppssww Compare string operands, words
ccwwdd Convert word to double
ddaaaa Decimal adjust AL after addition
ddaass Decimal adjust AL after subtraction
ddeeccbb _a Decrement by one, byte
ddeecc _a Decrement by one, word
ddiivvbb _m Unsigned divide, byte
ddiivv _m Unsigned divide, word
eesscc _a Escape 00xxDD88
hhlltt Halt
iiccaallll _a Near call, absolute offset at EA word
iiddiivvbb _m Signed divide, byte
iiddiivv _m Signed divide, word
iijjmmpp _a Jump short, absolute offset at EA word
iimmuullbb _m Signed multiply, byte
iimmuull _m Signed multiply, word
iinnbb _a_l, _p Input, byte
iinn _a_x, _p Input, word
iinnbb _a_l, _d_x Input, byte
iinn _a_x, _d_x Input, word
iinnccbb _a Increment by one, byte
iinncc _a Increment by one, word
iinntt _e Call to interrupt
iinnttoo Call to interrupt, overflow
iirreett Interrupt return
jjaa _d Jump short if greater
jjaaee _d Jump short if greater or equal
jjbb _d Jump short if less
jjbbee _d Jump short if less or equal
jjcc _d Jump short if carry
jjccxxzz _d Jump short if CX equals zero
jjee _d Jump short if equal to
jjgg _d Jump short if greater
jjggee _d Jump short if greater or equal
jjll _d Jump short if less
jjllee _d Jump short if less or equal
jjmmpp _d Jump short, PC-relative word offset
jjmmppbb _d Jump short, PC-relative byte offset
jjmmppll _d Jump long
COHERENT Lexicon Page 11
as Command as
jjnnaa _d Jump short if not above
jjnnaaee _d Jump short if not above or equal
jjnnbb _d Jump short if not below
jjnnbbee _d Jump short if not below or equal
jjnncc _d Jump short if not carry
jjnnee _d Jump short if not equal
jjnngg _d Jump short if not greater
jjnnggee _d Jump short if not greater or equal
jjnnll _d Jump short if not less
jjnnllee _d Jump short if not less or equal
jjnnoo _d Jump short if not overflow
jjnnpp _d Jump short if not parity
jjnnss _d Jump short if not sign
jjnnzz _d Jump short if not zero
jjoo _d Jump short if overflow
jjpp _d Jump short if parity
jjppee _d Jump short if parity even
jjppoo _d Jump short if parity odd
jjss _d Jump short if sign
jjzz _d Jump short if zero
llaahhff Load flags into AH register
llddss _r, _a Load double pointer into DS
lleeaa _r, _a Load effective address offset
lleess _r, _a Load double pointer into ES
lloocckk Assert BUS LOCK signal
llooddssbb Load byte into AL
llooddss Load byte into AL
llooddssww Load byte into AL
lloooopp _d Loop; decrement CX, jump short
if CX less than zero
llooooppee _d Loop; decrement CX, jump short
if CZ not zero and equal
llooooppnnee _d Loop; decrement CX, jump short
if CX not zero and not equal
llooooppnnzz _d Loop; decrement CX, jump short
if CZ not zero and ZF equals zero
llooooppzz _d Loop; decrement CX, jump short
if CX not zero and zero
mmoovvbb _r, _a Move, byte
mmoovv _r, _a Move, word
mmoovvbb _a, _r Move, byte
mmoovv _a, _r Move, word
mmoovvbb _a, $_e Move, byte
mmoovv _a, $_e Move, word
mmoovvbb _a, _s Move, byte
mmoovv _a, _s Move, word
mmoovvbb _s, _a Move, byte
mmoovv _s, _a Move, word
mmoovvssbb Move string byte-by-byte
mmoovvss Move string word-by-word
mmoovvssww Move string word-by-word
mmuullbb _m Multiply, byte
mmuull _m Multiply, word
nneeggbb _a Two's complement negation, byte
nneegg _a Two's complement negation, word
COHERENT Lexicon Page 12
as Command as
nnoopp No operation
nnoottbb _a One's complement negation, byte
nnoott _a One's complement negation, word
oorrbb _r, _a Logical inclusive OR, byte
oorr _r, _a Logical inclusive OR, word
oorrbb _a, _r Logical inclusive OR, byte
oorr _a, _r Logical inclusive OR, word
oorrbb _a, $_e Logical inclusive OR, byte
oorr _a, $_e Logical inclusive OR, word
oouuttbb _p, _a_l Output to port, byte
oouutt _p, _a_x Output to port, word
oouuttbb _d_x, _a_l Output to port, byte
oouutt _d_x, _a_x Output to port, word
ppoopp _m Pop a word from the stack
ppoopp _s Pop a word from the stack
ppooppff Pop from stack into flags register
ppuusshh _m Push a word onto the stack
ppuusshh _s Push a word onto the stack
ppuusshhff Push flags register onto the stack
rrccllbb _a, $_1 Rotate left $1 times, byte
rrccllbb _a, _c_l Rotate left CL times, byte
rrccll _a, $_1 Rotate left $1 times, word
rrccll _a, _c_l Rotate left CL times, word
rrccrrbb _a, $_1 Rotate right $1 times, byte
rrccrrbb _a, _c_l Rotate right CL times, byte
rrccrr _a, $_1 Rotate right $1 times, word
rrccrr _a, _c_l Rotate right CL times, word
rreepp Repeat following string operation
rreeppee Find nonmatching bytes
rreeppnnee Repeat, not equal
rreeppnnzz Repeat, not equal
rreeppzz Repeat, equal
rreett Return from procedure
rroollbb _a, $_1 Rotate left, byte
rroollbb _a, _c_l Rotate left, byte
rrooll _a, $_1 Rotate left, word
rrooll _a, _c_l Rotate left, word
rroorrbb _a, $_1 Rotate right, byte
rroorrbb _a, _c_l Rotate right, byte
rroorr _a, $_1 Rotate right, word
rroorr _a, _c_l Rotate right, word
ssaahhff Store AH into flags
ssaallbb _a, $_1 Shift left, byte
ssaallbb _a, _c_l Shift left, byte
ssaall _a, $_1 Shift left, word
ssaall _a, _c_l Shift left, word
ssaarrbb _a, $_1 Shift right, byte
ssaarrbb _a, _c_l Shift right, byte
ssaarr _a, $_1 Shift right, word
ssaarr _a, _c_l Shift right, word
ssbbbbbb _r, _a Integer subtract with borrow, byte
ssbbbb _r, _a Integer subtract with borrow, word
ssbbbbbb _a, _r Integer subtract with borrow, byte
ssbbbb _a, _r Integer subtract with borrow, word
ssbbbbbb _a, $_e Integer subtract with borrow, byte
COHERENT Lexicon Page 13
as Command as
ssbbbb _a, $_e Integer subtract with borrow, word
ssccaassbb Compare string data, byte
ssccaass Compare string data, word
sshhllbb _a, $_1 Shift left, byte
sshhllbb _a, _c_l Shift left, byte
sshhll _a, $_1 Shift left, word
sshhll _a, _c_l Shift left, word
sshhrrbb _a, $_1 Shift right, byte
sshhrrbb _a, _c_l Shift right, byte
sshhrr _a, $_1 Shift right, word
sshhrr _a, _c_l Shift right, word
ssttcc Set carry flag
ssttdd Set direction flag
ssttii Set interrupt enable flag
ssttoossbb Store string data, byte
ssttooss Store string data, byte or word
ssttoossww Store string data, word
ssuubbbb _r, _a Integer subtraction, byte
ssuubb _r, _a Integer subtraction, word
ssuubbbb _a, _r Integer subtraction, byte
ssuubb _a, _r Integer subtraction, word
ssuubbbb _a, $_e Integer subtraction, byte
ssuubb _a, $_e Integer subtraction, word
tteessttbb _r, _a Logical compare, byte
tteesstt _r, _a Logical compare, word
tteessttbb _a, _r Logical compare, byte
tteesstt _a, _r Logical compare, word
tteessttbb _a, $_e Logical compare, byte
tteesstt _a, $_e Logical compare, word
wwaaiitt Wait until BUSY pin is inactive
xxccaallll _d, _d Far call, immediate four-byte address
xxcchhggbb _r, _a Exchange memory, byte
xxcchhgg _r, _a Exchange memory, word
xxiiccaallll Far call, address at EA double word
xxiijjmmpp Jump far, address at memory double word
xxjjmmpp _d, _d Jump far, immediate four-byte address
xxllaatt Table look-up translation
xxoorrbb _r, _a Logical exclusive OR, byte
xxoorr _r, _a Logical exclusive OR, word
xxoorrbb _a, _r Logical exclusive OR, byte
xxoorr _a, _r Logical exclusive OR, word
xxoorrbb _a, $_e Logical exclusive OR, byte
xxoorr _a, $_e Logical exclusive OR, word
xxrreett Return, intersegment
***** 80286 Instructions *****
The following instructions implement 80286-specific actions.
Programs that use them cannot be run on 8086-based machines.
ppuusshhaa Push all general registers
ppooppaa Pop all general registers
iinnssbb Input byte from port DX to ES:(DI)
iinnss Input word from port DX to ES:(DI)
COHERENT Lexicon Page 14
as Command as
oouuttssbb Output byte from port DX from ES:(DI)
oouuttss Output word from port DX from ES:(DI)
eenntteerr $_e, $_e Make stack frame for procedure
lleeaavvee Tear down stack frame for procedure
bboouunndd _r, _e Check array index against bounds
ssllddtt _a Store Local Descriptor Table Register
ssttrr _a Store Task Register
llllddtt _a Load Local Descriptor Table Register
llttrr _a Load Task Register
vveerrrr _a Verify a segment for reading
vveerrww _a Verify a segment for writing
ssggddtt _m Store Global Descriptor Table register
ssiiddtt _m Store Interrupt Descriptor Table register
llggddtt _m Load Global Descriptor Table register
lliiddtt _m Load Interrupt Descriptor Table register
ssmmssww _a Store Machine Status Word
llmmssww _a Load Machine Status Word
llaarr _r,_a Load access rights byte
llssll _r,_a Load segment limit
ccllttss Clear Task Switched Flag
aarrppll Adjust RPL field of Selector
ppuusshh $_e Push sign extended byte
Also the $_1 forms become $_e on rol, rolb, ror, rorb, sal, salb,
shrb, shr, and shrb. This is because 8086 task of shifting and
rotating by an immediate value could only take an immediate value
of 1; however, on the 80286 the immediate value may be up to 31.
***** i8087 Op Codes *****
The assembler can also generate object files for use with the
i8087 mathematics co-processor. The following listing presents
the assembly language op codes for this feature. sstt00 indicates
floating point register 0 and sstt11 indicates any floating point
register but 0; dd is the same as in the above listing.
_d Direct address
_s_t_0Floating point register 0
_s_t_1Any floating point register _e_x_c_e_p_t 0
The following lists the i8087 instructions:
ffaabbss Absolute value
ffaadddd _s_t_0, _s_t_1Add real
ffaadddd _s_t_1, _s_t_0Add real
ffffaadddd _d Add real, float
ffddaadddd _d Add real, double
ffaaddddpp Add real and pop
COHERENT Lexicon Page 15
as Command as
ffaaddddpp _s_t, _s_t_0 Add real and pop
ffbblldd _d Load packed decimal (BCD)
ffbbssttpp _d Store packed decimal (BCD) and pop
ffcchhss Change sign
ffcclleexx Clear exception
ffnncclleexx Clear exception
ffccoomm Compare real
ffffccoomm _d Compare real, float
ffddccoomm _d Compare real, double
ffccoommpp Compare real and pop
ffccoommpp st1 Compare real and pop
ffffccoommpp _d Compare real and pop, float
ffddccoommpp _d Compare real and pop, double
ffccoommpppp Compare real and pop twice
ffddeeccssttpp Decrement stack pointer
ffddiissii Disable interrupts
ffnnddiissii Disable interrupts, no operands
ffddiivv _s_t_0, _s_t_1Divide real
ffddiivv _s_t_1, _s_t_0Divide real
ffffddiivv _d Divide real, float
ffddddiivv _d Divide real, double
ffddiivvpp Divide real and pop
ffddiivvpp st1 Divide real and pop
ffddiivvrr _s_t_0, _s_t_1Divide real reversed
ffddiivvrr _s_t_1, _s_t_0Divide real reversed
ffffddiivvrr _d Divide real reversed, float
ffddddiivvrr _d Divide real reversed, double
ffddiivvrrpp Divide real reversed and pop
ffddiivvrrpp _s_t_1 Divide real reversed and pop
ffeennii Enable interrupts
ffnneennii Enable interrupts, no operands
ffffrreeee _s_t_1 Free register
ffiiaadddd _d Integer add
ffllaadddd _d Integer add, long
ffiiccoomm _d Integer compare
ffllccoomm _d Integer compare, long
ffiiccoommpp _d Integer compare and pop
ffllccoommpp _d Integer compare and pop, long
ffiiddiivv _d Integer divide
ffllddiivv _d Integer divide, long
ffiiddiivvrr _d Integer divide reversed
ffllddiivvrr _d Integer divide, long reversed
ffiilldd _d Integer load
fflllldd _d Integer load, long
ffqqlldd _d Integer load, quad
ffiimmuull _d Integer multiply
ffllmmuull _d Integer multiply, long
ffiinnccssttpp Increment stack pointer
ffiinniitt Initialize processor
ffnniinniitt Initialize processor
ffiisstt _d Integer store
ffllsstt _d Integer store, long
ffiissttpp _d Integer store and pop
ffllssttpp _d Integer store and pop, long
ffqqssttpp _d Integer store and pop, quad
COHERENT Lexicon Page 16
as Command as
ffiissuubb _d Integer subtract
ffllssuubb _d Integer subtract, long
ffiissuubbrr _d Integer subtract reversed
ffllssuubbrr _d Integer subtract reversed, long
fflldd _s_t_1 Load real
fffflldd _d Load real, float
ffddlldd _d Load real, double
ffttlldd _d Load real, temp
ffllddccww _d Load control word
ffllddeennvv _d Load environment
ffllddllgg22 Load log(10)2
ffllddllnn22 Load log(e)2
ffllddll22ee Load log(2)e
ffllddll22tt Load log(2)10
ffllddppii Load pi
ffllddzz Load +0.0
fflldd11 Load +1.0
ffmmuull Multiply real
ffmmuull _s_t_0, _s_t_1Multiply real
ffffmmuull _s_t_1, _s_t_0Multiply real, float
ffddmmuull _d Multiply real, double
ffmmuullpp _d Multiply real and pop
ffnnoopp st1 No operation
ffppaattaann Partial arctangent
ffpprreemm Partial remainder
ffppttaann Partial tangent
ffrrnnddiinntt Round to integer
ffrrssttoorr _d Restore saved state
ffssaavvee _d Save state
ffnnssaavvee _d Save state
ffssccaallee Scale
ffsseettppmm Set protected mode
ffssqqrrtt Square root
ffsstt _s_t_1 Store real
ffffsstt _d Store real, float
ffddsstt _d Store real, double
ffssttccww _d Store control word
ffnnssttccww _d Store control word
ffsstteennvv _d Store environment
ffnnsstteennvv _d Store environment
ffssttpp _s_t_1 Store real and pop
ffffssttpp _d Store real and pop, float
ffddssttpp _d Store real and pop, double
ffttssttpp _d Store real and pop, temp
ffssttssww _d Store status word
ffnnssttssww _d Store status word
ffssuubb _s_t_0, _s_t_1Subtract real
ffssuubb _s_t_1, _s_t_0Subtract real
ffffssuubb _d Subtract real, float
ffddssuubb _d Subtract real, double
ffssuubbpp Subtract real and pop
ffssuubbpp _s_t_1 Subtract real and pop
ffssuubbrr _d Subtract real reversed
ffffssuubbrr _d Subtract real reversed, float
ffddssuubbrr _d Subtract real reversed, double
COHERENT Lexicon Page 17
as Command as
ffssuubbrrpp Subtract real reversed and pop
ffssuubbrrpp _s_t_1 Subtract real reversed and pop
ffttsstt Test stack top against +0.0
ffwwaaiitt Wait while 8087 is busy
ffxxaamm Examine stack top
ffxxcchh _s_t_1 Exchange registers
ffxxcchh Exchange registers
ffxxttrraacctt Extract exponent and significance
ffyyll22xx Y*log(2)X
ffyyll22xxpp11 Y*log(2)(X+1)
***** C Compiler Conventions *****
as is often used to write small functions that perform tasks not
easily or efficiently done in C. Such functions are intended to
be called from a C program. As long as the assembly language
source code follows compiler conventions, the assembler routine
will be fully compatible with C functions. These conventions are
(1) the names of external variables and (2) calling functions.
***** Naming Conventions *****
The C compiler appends an underline character `_' to the end of
every external declared in a C source file. When referring to
any external variable or function declared in a C source file,
append an underscore to the name. In a similar manner, when
defining a function or variable in an assembly language source
file that is to be accessed from a C source file, append an un-
derline character.
***** Function-Calling Conventions *****
Function-calling conventions deal with how arguments are passed
to functions, how values are returned, and which registers are
used for special purposes and must be protected.
***** Arguments *****
Function arguments are passed on the stack. They are pushed by
the calling function, which also removes them when the called
function returns. Looking at the declaration of the function,
the order in which they are pushed onto the stack is from right
to left; that is, the C compiler pushes the argument list in
reverse order of declaration. The instruction call to jump to
the function also pushes the return address, so that when the
called routine gains control the first argument is found at of-
fset 2 from the stack pointer.
Integer and pointer arguments are word size, and are simply
pushed with a push instruction. Characters, although byte size,
are not passed as bytes. The C language requires that char
variables be promoted to the type int before being passed. The
promotion is signed or unsigned, depending on the type of the
char variable. lloonnggs are pushed one word at a time; the higher-
address word is pushed first. This ensures that the words of the
COHERENT Lexicon Page 18
as Command as
long are in the correct order on the stack, because the stack
grows toward low-addressed memory.
Passing ffllooaatts, ddoouubbllees, or structure arguments is more involved.
C requires ffllooaatts to be promoted to and passed as ddoouubbllees, so
this conversion must be performed first. ddoouubbllees and structures
are passed so that as they sit on the stack, all bytes are in the
correct order; this is analogous to the passing of lloonnggs. This
means, for example, that ddoouubbllees may be pushed with four push
word instructions, beginning with the highest addressed word in
the 64-bit double, and ending with the lowest addressed word.
If in doubt about how to apply any of this, try writing a simple
C program that uses what you need, and compile it with the -vasm
option to the cc command. This produces an assembly-language
version of the C program, which can be studied to see exactly
what the compiler does, and mimicked to good effect.
***** Return Values *****
Functions return values in various registers according to their
type. iinntts and pointers are returned in the ax register. cchhaarrs
are returned by first promoting them to iinntts and returning the
result in the ax register; effectively, this means that cchhaarrs are
returned in the al register. lloonnggs are returned in the dx:ax
register pair, with the most significant word (also the high-ad-
dress word) in the dx register, and the least significant word in
the ax register.
ffllooaatts, ddoouubbllees, and structures are returned in a more complex
fashion. C requires ffllooaatts be returned as ddoouubbllees, so they are
converted. ddoouubbllees are returned in a special eight-byte array
named _ffppaacc (of course, in assembly language the name is _ffppaacc_).
This array is defined by the compiler. In the event that a func-
tion returns a structure, the contents of the structure are saved
in memory, and the function returns a pointer to that structure
in the ax register. The calling function then moves the bytes
into the actual destination.
Again, if in doubt about how to do this in assembly language, try
compiling a function with assembly language output to see how the
compiler does it.
***** Important Registers *****
Every function must preserve the value of the bp register, which
is the caller's stack frame pointer. Also, the compiler uses the
si and di registers for register variables, so they must be
preserved.
***** Example of an Assembly Language Program *****
The following assembly language file, strchar.s defines a func-
tion strchar that returns the number of occurrences of a charac-
COHERENT Lexicon Page 19
as Command as
ter in a string.
FILE: strchar.s
/
/
/ Count and return the occurrences
/ of a character in a string.
/
/ int
/ strchar(s, c)
/ char *s;
/ int c;
/
/
.globl strchar_ / Make the name known externally.
strchar_:
push si / Standard C function
push di / linkage. Save the
push bp / si, di, and bp registers
mov bp, sp / and set up new frame pointer.
mov si, 8(bp) / String ptr -> si.
mov bx, 10(bp) / Char -> bx (actually bl).
sub ax, ax / Clear ax (count register).
sub cx, cx / Clear cx.
0: movb cl, (si) / Get character from string.
jcxz 2f / End of string?
cmpb bl, cl / No. Do chars match?
jnz 1f / No.
inc ax / Yes. Increment count.
1: inc si / Bump string pointer
jmp 0b / and loop again.
2: pop bp / Standard C return
pop di / linkage. Restore
pop si / saved registers and
ret / go home.
COHERENT Lexicon Page 20
as Command as
The following C program, main.c uses strchar The assembly lan-
guage listing that follows, main.s was produced from main.c by
the -vasm option in cc. The listing has been edited, and com-
ments added, to illustrate what is happening.
FILE: main.c
main()
{
int n;
n = strchar("aardvark", 'a');
}
FILE: main.s
.shri / ``code'' program section.
.globl main_
main_:
.strn / ``string'' program section.
L2: .byte 0x61 / This is the string
.byte 0x61 / ``aardvark''
.byte 0x72
.byte 0x64
.byte 0x76
.byte 0x61
.byte 0x72
.byte 0x6B
.byte 0x00
.shri / Back to ``code''
push si / Standard C function
push di / linkage. Save registers,
push bp / set up new frame pointer (bp),
mov bp, sp / and make room on stack
sub sp, $0x02 / for the auto int, ``n''
COHERENT Lexicon Page 21
as Command as
mov ax, $0x61 / Push the
push ax / character `a'.
mov ax, $L2 / Push the address
push ax / of the string ``aardvark''
call strchar_ / Function call.
add sp, $0x04 / Remove args from stack.
mov -0x02(bp), ax / Assign result to auto `n'.
mov sp, bp / Standard C return
pop bp / linkage. Adjust stack
pop di / pointer, then restore
pop si / registers and
ret / go home.
***** Diagnostics *****
All errors detected by the assembler are reported on the screen
as an error message that is tagged with a line number. If a sym-
bol is associated with the error message (for example, if a sym-
bol is undefined), then the symbol's name is also given. If more
than one input file appears on the command line, error messages
are tagged with the name of the source file.
If a listing is generated, errors are reported on the listing in
the same format, with the error flags at the left margin. The
total number of errors is displayed on the screen at the end of
the assembly.
For a full listing of aass error messages, see the tutorial for the
C compiler, which appears earlier in this manual.
***** See Also *****
cc, commands
COHERENT Lexicon Page 22
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.