<s>
x86	B-Language
assembly	I-Language
language	I-Language
is	O
the	O
name	O
for	O
the	O
family	O
of	O
assembly	B-Language
languages	I-Language
which	O
provide	O
some	O
level	O
of	O
backward	B-General_Concept
compatibility	I-General_Concept
with	O
CPUs	O
back	O
to	O
the	O
Intel	B-General_Concept
8008	I-General_Concept
microprocessor	O
,	O
which	O
was	O
launched	O
in	O
April	O
1972	O
.	O
</s>
<s>
It	O
is	O
used	O
to	O
produce	O
object	B-Language
code	I-Language
for	O
the	O
x86	B-Operating_System
class	O
of	O
processors	O
.	O
</s>
<s>
Regarded	O
as	O
a	O
programming	O
language	O
,	O
assembly	O
is	O
machine-specific	O
and	O
low-level	B-Language
.	O
</s>
<s>
Like	O
all	O
assembly	B-Language
languages	I-Language
,	O
x86	B-Language
assembly	I-Language
uses	O
mnemonics	O
to	O
represent	O
fundamental	O
CPU	B-Language
instructions	I-Language
,	O
or	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
Assembly	B-Language
languages	I-Language
are	O
most	O
often	O
used	O
for	O
detailed	O
and	O
time-critical	O
applications	O
such	O
as	O
small	O
real-time	B-Operating_System
embedded	B-Architecture
systems	I-Architecture
,	O
operating-system	B-General_Concept
kernels	B-Operating_System
,	O
and	O
device	B-Application
drivers	I-Application
,	O
but	O
can	O
also	O
be	O
used	O
for	O
other	O
applications	O
.	O
</s>
<s>
A	O
compiler	B-Language
will	O
sometimes	O
produce	O
assembly	B-Language
code	I-Language
as	O
an	O
intermediate	O
step	O
when	O
translating	O
a	O
high-level	B-Language
program	I-Language
into	O
machine	B-Language
code	I-Language
.	O
</s>
<s>
Each	O
x86	B-Device
assembly	I-Device
instruction	I-Device
is	O
represented	O
by	O
a	O
mnemonic	O
which	O
,	O
often	O
combined	O
with	O
one	O
or	O
more	O
operands	O
,	O
translates	O
to	O
one	O
or	O
more	O
bytes	O
called	O
an	O
opcode	B-Language
;	O
the	O
NOP	B-Language
instruction	O
translates	O
to	O
0x90	O
,	O
for	O
instance	O
,	O
and	O
the	O
HLT	B-Language
instruction	I-Language
translates	O
to	O
0xF4	O
.	O
</s>
<s>
There	O
are	O
potential	O
opcodes	B-Language
with	O
no	O
documented	O
mnemonic	O
which	O
different	O
processors	O
may	O
interpret	O
differently	O
,	O
making	O
a	O
program	O
using	O
them	O
behave	O
inconsistently	O
or	O
even	O
generate	O
an	O
exception	O
on	O
some	O
processors	O
.	O
</s>
<s>
These	O
opcodes	B-Language
often	O
turn	O
up	O
in	O
code	O
writing	O
competitions	O
as	O
a	O
way	O
to	O
make	O
the	O
code	O
smaller	O
,	O
faster	O
,	O
more	O
elegant	O
or	O
just	O
show	O
off	O
the	O
author	O
's	O
prowess	O
.	O
</s>
<s>
x86	B-Language
assembly	I-Language
language	I-Language
has	O
two	O
main	O
syntax	O
branches	O
:	O
Intel	O
syntax	O
and	O
AT&T	O
syntax	O
.	O
</s>
<s>
Intel	O
syntax	O
is	O
dominant	O
in	O
the	O
DOS	B-Device
and	O
Windows	B-Application
world	O
,	O
and	O
ATT	O
syntax	O
is	O
dominant	O
in	O
the	O
Unix	B-Application
world	O
,	O
since	O
Unix	B-Application
was	O
created	O
at	O
AT&T	O
Bell	O
Labs	O
.	O
</s>
<s>
add	O
esp	O
,	O
4	O
Derived	O
from	O
the	O
name	O
of	O
the	O
register	B-General_Concept
that	O
is	O
used	O
(	O
e.g.	O
</s>
<s>
The	O
assembler	B-Language
automatically	O
detects	O
the	O
type	O
of	O
symbols	O
;	O
i.e.	O
,	O
whether	O
they	O
are	O
registers	O
,	O
constants	O
or	O
something	O
else	O
.	O
</s>
<s>
Effective	O
addresses	B-General_Concept
movl	O
offset( %ebx	O
,	O
%ecx	O
,	O
4	O
)	O
,	O
%eax	O
General	O
syntax	O
of	O
DISP(BASE,INDEX,SCALE )	O
.	O
</s>
<s>
Many	O
x86	B-Operating_System
assemblers	B-Language
use	O
Intel	O
syntax	O
,	O
including	O
FASM	B-Application
,	O
MASM	B-Application
,	O
NASM	B-Application
,	O
TASM	B-Application
,	O
and	O
YASM	O
.	O
</s>
<s>
GAS	B-Application
,	O
which	O
originally	O
used	O
AT&T	O
syntax	O
,	O
has	O
supported	O
both	O
syntaxes	O
since	O
version	O
2.10	O
via	O
the	O
.intel_syntax	O
directive	O
.	O
</s>
<s>
A	O
quirk	O
in	O
the	O
ATT	O
syntax	O
for	O
x86	B-Operating_System
is	O
that	O
x87	B-Application
operands	O
are	O
reversed	O
,	O
an	O
inherited	O
bug	O
from	O
the	O
original	O
AT&T	O
assembler	B-Language
.	O
</s>
<s>
The	O
Intel	O
syntax	O
is	O
specific	O
to	O
the	O
x86	B-Operating_System
architecture	I-Operating_System
,	O
and	O
is	O
the	O
one	O
used	O
in	O
the	O
x86	B-Operating_System
platform	O
's	O
documentation	O
.	O
</s>
<s>
x86	B-Operating_System
processors	O
have	O
a	O
collection	O
of	O
registers	O
available	O
to	O
be	O
used	O
as	O
stores	O
for	O
binary	O
data	O
.	O
</s>
<s>
Collectively	O
the	O
data	O
and	O
address	B-General_Concept
registers	I-General_Concept
are	O
called	O
the	O
general	O
registers	O
.	O
</s>
<s>
Each	O
register	B-General_Concept
has	O
a	O
special	O
purpose	O
in	O
addition	O
to	O
what	O
they	O
can	O
all	O
do	O
:	O
</s>
<s>
extra	O
extension	O
registers	O
(	O
MMX	B-Architecture
,	O
3DNow	O
!,	O
SSE	B-General_Concept
,	O
etc	O
.	O
)	O
</s>
<s>
The	O
IP	O
register	B-General_Concept
points	O
to	O
the	O
memory	O
offset	O
of	O
the	O
next	B-General_Concept
instruction	I-General_Concept
in	O
the	O
code	O
segment	O
(	O
it	O
points	O
to	O
the	O
first	O
byte	O
of	O
the	O
instruction	O
)	O
.	O
</s>
<s>
The	O
IP	O
register	B-General_Concept
cannot	O
be	O
accessed	O
by	O
the	O
programmer	O
directly	O
.	O
</s>
<s>
The	O
x86	B-Operating_System
registers	O
can	O
be	O
used	O
by	O
using	O
the	O
MOV	O
instructions	O
.	O
</s>
<s>
The	O
x86	B-Operating_System
architecture	I-Operating_System
in	O
real	B-Application
and	O
virtual	B-Application
8086	I-Application
mode	I-Application
uses	O
a	O
process	O
known	O
as	O
segmentation	O
to	O
address	B-General_Concept
memory	O
,	O
not	O
the	O
flat	B-General_Concept
memory	I-General_Concept
model	I-General_Concept
used	O
in	O
many	O
other	O
environments	O
.	O
</s>
<s>
Segmentation	O
involves	O
composing	O
a	O
memory	B-General_Concept
address	I-General_Concept
from	O
two	O
parts	O
,	O
a	O
segment	O
and	O
an	O
offset	O
;	O
the	O
segment	O
points	O
to	O
the	O
beginning	O
of	O
a	O
64	O
KB	O
(	O
64×210	O
)	O
group	O
of	O
addresses	B-General_Concept
and	O
the	O
offset	O
determines	O
how	O
far	O
from	O
this	O
beginning	O
address	B-General_Concept
the	O
desired	O
address	B-General_Concept
is	O
.	O
</s>
<s>
In	O
segmented	O
addressing	O
,	O
two	O
registers	O
are	O
required	O
for	O
a	O
complete	O
memory	B-General_Concept
address	I-General_Concept
.	O
</s>
<s>
In	O
order	O
to	O
translate	O
back	O
into	O
a	O
flat	O
address	B-General_Concept
,	O
the	O
segment	O
value	O
is	O
shifted	O
four	O
bits	O
left	O
(	O
equivalent	O
to	O
multiplication	O
by	O
24	O
or	O
16	O
)	O
then	O
added	O
to	O
the	O
offset	O
to	O
form	O
the	O
full	O
address	B-General_Concept
,	O
which	O
allows	O
breaking	O
the	O
64k	B-Device
barrier	I-Device
through	O
clever	O
choice	O
of	O
addresses	B-General_Concept
,	O
though	O
it	O
makes	O
programming	O
considerably	O
more	O
complex	O
.	O
</s>
<s>
In	O
real	O
mode/protected	O
only	O
,	O
for	O
example	O
,	O
if	O
DS	O
contains	O
the	O
hexadecimal	O
number	O
0xDEAD	O
and	O
DX	O
contains	O
the	O
number	O
0xCAFE	O
they	O
would	O
together	O
point	O
to	O
the	O
memory	B-General_Concept
address	I-General_Concept
0xDEAD	O
*	O
0x10	O
+	O
0xCAFE	O
=	O
0xEB5CE	O
.	O
</s>
<s>
Therefore	O
,	O
the	O
CPU	O
can	O
address	B-General_Concept
up	O
to	O
1,048,576	O
bytes	O
(	O
1	O
MB	O
)	O
in	O
real	B-Application
mode	I-Application
.	O
</s>
<s>
By	O
combining	O
segment	O
and	O
offset	O
values	O
we	O
find	O
a	O
20-bit	O
address	B-General_Concept
.	O
</s>
<s>
The	O
original	O
IBM	O
PC	O
restricted	O
programs	O
to	O
640	O
KB	O
but	O
an	O
expanded	B-Device
memory	I-Device
specification	O
was	O
used	O
to	O
implement	O
a	O
bank	O
switching	O
scheme	O
that	O
fell	O
out	O
of	O
use	O
when	O
later	O
operating	B-General_Concept
systems	I-General_Concept
,	O
such	O
as	O
Windows	B-Application
,	O
used	O
the	O
larger	O
address	B-General_Concept
ranges	O
of	O
newer	O
processors	O
and	O
implemented	O
their	O
own	O
virtual	B-Architecture
memory	I-Architecture
schemes	O
.	O
</s>
<s>
Protected	B-Application
mode	I-Application
,	O
starting	O
with	O
the	O
Intel	B-General_Concept
80286	I-General_Concept
,	O
was	O
utilized	O
by	O
OS/2	B-Application
.	O
</s>
<s>
Several	O
shortcomings	O
,	O
such	O
as	O
the	O
inability	O
to	O
access	O
the	O
BIOS	B-Operating_System
and	O
the	O
inability	O
to	O
switch	O
back	O
to	O
real	B-Application
mode	I-Application
without	O
resetting	O
the	O
processor	O
,	O
prevented	O
widespread	O
usage	O
.	O
</s>
<s>
The	O
80286	B-General_Concept
was	O
also	O
still	O
limited	O
to	O
addressing	O
memory	O
in	O
16-bit	B-Device
segments	O
,	O
meaning	O
only	O
216	O
bytes	O
(	O
64	O
kilobytes	O
)	O
could	O
be	O
accessed	O
at	O
a	O
time	O
.	O
</s>
<s>
To	O
access	O
the	O
extended	O
functionality	O
of	O
the	O
80286	B-General_Concept
,	O
the	O
operating	B-General_Concept
system	I-General_Concept
would	O
set	O
the	O
processor	O
into	O
protected	B-Application
mode	I-Application
,	O
enabling	O
24-bit	O
addressing	O
and	O
thus	O
224	O
bytes	O
of	O
memory	O
(	O
16	O
megabytes	O
)	O
.	O
</s>
<s>
In	O
protected	B-Application
mode	I-Application
,	O
the	O
segment	B-Device
selector	I-Device
can	O
be	O
broken	O
down	O
into	O
three	O
parts	O
:	O
a	O
13-bit	O
index	O
,	O
a	O
Table	O
Indicator	O
bit	O
that	O
determines	O
whether	O
the	O
entry	O
is	O
in	O
the	O
GDT	B-General_Concept
or	O
LDT	B-General_Concept
and	O
a	O
2-bit	O
Requested	O
Privilege	O
Level	O
;	O
see	O
x86	B-Device
memory	I-Device
segmentation	I-Device
.	O
</s>
<s>
When	O
referring	O
to	O
an	O
address	B-General_Concept
with	O
a	O
segment	O
and	O
an	O
offset	O
the	O
notation	O
of	O
segment:offset	B-Device
is	O
used	O
,	O
so	O
in	O
the	O
above	O
example	O
the	O
flat	O
address	B-General_Concept
0xEB5CE	O
can	O
be	O
written	O
as	O
0xDEAD:0xCAFE	O
or	O
as	O
a	O
segment	O
and	O
offset	O
register	B-General_Concept
pair	O
;	O
DS:DX	O
.	O
</s>
<s>
There	O
are	O
some	O
special	O
combinations	O
of	O
segment	B-Device
registers	I-Device
and	O
general	O
registers	O
that	O
point	O
to	O
important	O
addresses	B-General_Concept
:	O
</s>
<s>
CS:IP	O
(	O
CS	O
is	O
Code	O
Segment	O
,	O
IP	O
is	O
Instruction	B-General_Concept
Pointer	I-General_Concept
)	O
points	O
to	O
the	O
address	B-General_Concept
where	O
the	O
processor	O
will	O
fetch	O
the	O
next	O
byte	O
of	O
code	O
.	O
</s>
<s>
SS	O
:	O
SP	O
(	O
SS	O
is	O
Stack	B-Application
Segment	O
,	O
SP	O
is	O
Stack	B-Application
Pointer	O
)	O
points	O
to	O
the	O
address	B-General_Concept
of	O
the	O
top	O
of	O
the	B-Application
stack	I-Application
,	O
i.e.	O
</s>
<s>
The	O
Intel	B-General_Concept
80386	I-General_Concept
featured	O
three	O
operating	O
modes	O
:	O
real	B-Application
mode	I-Application
,	O
protected	B-Application
mode	I-Application
and	O
virtual	O
mode	O
.	O
</s>
<s>
The	O
protected	B-Application
mode	I-Application
which	O
debuted	O
in	O
the	O
80286	B-General_Concept
was	O
extended	O
to	O
allow	O
the	O
80386	B-General_Concept
to	O
address	B-General_Concept
up	O
to	O
4	O
GB	O
of	O
memory	O
,	O
the	O
all	O
new	O
virtual	B-Application
8086	I-Application
mode	I-Application
(	O
VM86	B-Application
)	O
made	O
it	O
possible	O
to	O
run	O
one	O
or	O
more	O
real	B-Application
mode	I-Application
programs	O
in	O
a	O
protected	O
environment	O
which	O
largely	O
emulated	O
real	B-Application
mode	I-Application
,	O
though	O
some	O
programs	O
were	O
not	O
compatible	O
(	O
typically	O
as	O
a	O
result	O
of	O
memory	B-General_Concept
addressing	I-General_Concept
tricks	O
or	O
using	O
unspecified	O
op-codes	B-Language
)	O
.	O
</s>
<s>
The	O
32-bit	O
flat	B-General_Concept
memory	I-General_Concept
model	I-General_Concept
of	O
the	O
80386	B-General_Concept
's	O
extended	O
protected	B-Application
mode	I-Application
may	O
be	O
the	O
most	O
important	O
feature	O
change	O
for	O
the	O
x86	B-Operating_System
processor	O
family	O
until	O
AMD	O
released	O
x86-64	B-Device
in	O
2003	O
,	O
as	O
it	O
helped	O
drive	O
large	O
scale	O
adoption	O
of	O
Windows	B-Application
3.1	O
(	O
which	O
relied	O
on	O
protected	B-Application
mode	I-Application
)	O
since	O
Windows	B-Application
could	O
now	O
run	O
many	O
applications	O
at	O
once	O
,	O
including	O
DOS	B-Device
applications	O
,	O
by	O
using	O
virtual	B-Architecture
memory	I-Architecture
and	O
simple	O
multitasking	B-Operating_System
.	O
</s>
<s>
The	O
x86	B-Operating_System
processors	O
support	O
five	O
modes	O
of	O
operation	O
for	O
x86	B-Operating_System
code	O
,	O
Real	B-Application
Mode	I-Application
,	O
Protected	B-Application
Mode	I-Application
,	O
Long	B-Application
Mode	I-Application
,	O
Virtual	O
86	O
Mode	O
,	O
and	O
System	B-Architecture
Management	I-Architecture
Mode	I-Architecture
,	O
in	O
which	O
some	O
instructions	O
are	O
available	O
and	O
others	O
are	O
not	O
.	O
</s>
<s>
A	O
16-bit	B-Device
subset	O
of	O
instructions	O
is	O
available	O
on	O
the	O
16-bit	B-Device
x86	B-Operating_System
processors	O
,	O
which	O
are	O
the	O
8086	O
,	O
8088	O
,	O
80186	O
,	O
80188	O
,	O
and	O
80286	B-General_Concept
.	O
</s>
<s>
These	O
instructions	O
are	O
available	O
in	O
real	B-Application
mode	I-Application
on	O
all	O
x86	B-Operating_System
processors	O
,	O
and	O
in	O
16-bit	B-Device
protected	B-Application
mode	I-Application
(	O
80286	B-General_Concept
onwards	O
)	O
,	O
additional	O
instructions	O
relating	O
to	O
protected	B-Application
mode	I-Application
are	O
available	O
.	O
</s>
<s>
On	O
the	O
80386	B-General_Concept
and	O
later	O
,	O
32-bit	O
instructions	O
(	O
including	O
later	O
extensions	O
)	O
are	O
also	O
available	O
in	O
all	O
modes	O
,	O
including	O
real	B-Application
mode	I-Application
;	O
on	O
these	O
CPUs	O
,	O
V86	B-Application
mode	I-Application
and	O
32-bit	O
protected	B-Application
mode	I-Application
are	O
added	O
,	O
with	O
additional	O
instructions	O
provided	O
in	O
these	O
modes	O
to	O
manage	O
their	O
features	O
.	O
</s>
<s>
Finally	O
,	O
in	O
long	B-Application
mode	I-Application
(	O
AMD	B-General_Concept
Opteron	I-General_Concept
onwards	O
)	O
,	O
64-bit	O
instructions	O
,	O
and	O
more	O
registers	O
,	O
are	O
also	O
available	O
.	O
</s>
<s>
The	O
instruction	O
set	O
is	O
similar	O
in	O
each	O
mode	O
but	O
memory	B-General_Concept
addressing	I-General_Concept
and	O
word	O
size	O
vary	O
,	O
requiring	O
different	O
programming	O
strategies	O
.	O
</s>
<s>
The	O
modes	O
in	O
which	O
x86	B-Operating_System
code	O
can	O
be	O
executed	O
in	O
are	O
:	O
</s>
<s>
20-bit	O
segmented	O
memory	B-General_Concept
address	I-General_Concept
space	O
(	O
meaning	O
that	O
only	O
1	O
MB	O
of	O
memory	O
can	O
be	O
addressed	O
—	O
actually	O
,	O
slightly	O
more	O
)	O
,	O
direct	O
software	O
access	O
to	O
peripheral	O
hardware	O
,	O
and	O
no	O
concept	O
of	O
memory	B-General_Concept
protection	I-General_Concept
or	O
multitasking	B-Operating_System
at	O
the	O
hardware	O
level	O
.	O
</s>
<s>
Computers	O
that	O
use	O
BIOS	B-Operating_System
start	O
up	O
in	O
this	O
mode	O
.	O
</s>
<s>
Expands	O
addressable	O
physical	O
memory	O
to	O
16	O
MB	O
and	O
addressable	O
virtual	B-Architecture
memory	I-Architecture
to	O
1	O
GB	O
.	O
</s>
<s>
Provides	O
privilege	B-Operating_System
levels	I-Operating_System
and	O
protected	B-General_Concept
memory	I-General_Concept
,	O
which	O
prevents	O
programs	O
from	O
corrupting	O
one	O
another	O
.	O
</s>
<s>
16-bit	B-Device
protected	B-Application
mode	I-Application
(	O
used	O
during	O
the	O
end	O
of	O
the	O
DOS	B-Device
era	O
)	O
used	O
a	O
complex	O
,	O
multi-segmented	O
memory	O
model	O
.	O
</s>
<s>
32-bit	O
protected	B-Application
mode	I-Application
uses	O
a	O
simple	O
,	O
flat	B-General_Concept
memory	I-General_Concept
model	I-General_Concept
.	O
</s>
<s>
Mostly	O
an	O
extension	O
of	O
the	O
32-bit	O
(	O
protected	B-Application
mode	I-Application
)	O
instruction	O
set	O
,	O
but	O
unlike	O
the	O
16	O
–	O
to	O
–	O
32-bit	O
transition	O
,	O
many	O
instructions	O
were	O
dropped	O
in	O
the	O
64-bit	O
mode	O
.	O
</s>
<s>
It	O
is	O
intended	O
for	O
use	O
only	O
by	O
system	O
firmware	B-Application
.	O
</s>
<s>
All	O
normal	O
execution	O
,	O
including	O
the	O
operating	B-General_Concept
system	I-General_Concept
,	O
is	O
suspended	O
.	O
</s>
<s>
An	O
alternate	O
software	O
system	O
(	O
which	O
usually	O
resides	O
in	O
the	O
computer	O
's	O
firmware	B-Application
,	O
or	O
a	O
hardware-assisted	O
debugger	B-Application
)	O
is	O
then	O
executed	O
with	O
high	O
privileges	O
.	O
</s>
<s>
The	O
processor	O
runs	O
in	O
real	B-Application
mode	I-Application
immediately	O
after	O
power	O
on	O
,	O
so	O
an	O
operating	B-Operating_System
system	I-Operating_System
kernel	I-Operating_System
,	O
or	O
other	O
program	O
,	O
must	O
explicitly	O
switch	O
to	O
another	O
mode	O
if	O
it	O
wishes	O
to	O
run	O
in	O
anything	O
but	O
real	B-Application
mode	I-Application
.	O
</s>
<s>
Switching	O
modes	O
is	O
accomplished	O
by	O
modifying	O
certain	O
bits	O
of	O
the	O
processor	O
's	O
control	B-Operating_System
registers	I-Operating_System
after	O
some	O
preparation	O
,	O
and	O
some	O
additional	O
setup	O
may	O
be	O
required	O
after	O
the	O
switch	O
.	O
</s>
<s>
With	O
a	O
computer	O
running	O
legacy	B-Operating_System
BIOS	I-Operating_System
,	O
the	O
BIOS	B-Operating_System
and	O
the	O
boot	B-Application
loader	I-Application
is	O
running	O
in	O
Real	B-Application
mode	I-Application
,	O
then	O
the	O
64-bit	O
operating	B-Operating_System
system	I-Operating_System
kernel	I-Operating_System
checks	O
and	O
switches	O
the	O
CPU	O
into	O
Long	B-Application
mode	I-Application
and	O
then	O
starts	O
new	O
kernel-mode	B-Operating_System
threads	O
running	O
64-bit	O
code	O
.	O
</s>
<s>
With	O
a	O
computer	O
running	O
UEFI	B-Architecture
,	O
the	O
UEFI	B-Architecture
firmware	I-Architecture
(	O
except	O
CSM	O
and	O
legacy	O
Option	B-Device
ROM	I-Device
)	O
,	O
the	O
UEFI	B-Architecture
boot	B-Application
loader	I-Application
and	O
the	O
UEFI	B-Architecture
operating	B-Operating_System
system	I-Operating_System
kernel	I-Operating_System
is	O
all	O
running	O
in	O
Long	B-Application
mode	I-Application
.	O
</s>
<s>
In	O
general	O
,	O
the	O
features	O
of	O
the	O
modern	O
x86	B-Device
instruction	I-Device
set	I-Device
are	O
:	O
</s>
<s>
Mainly	O
one-address	O
and	O
two-address	O
instructions	O
,	O
that	O
is	O
to	O
say	O
,	O
the	O
first	O
operand	O
is	O
also	O
the	O
destination	O
.	O
</s>
<s>
Memory	O
operands	O
as	O
both	O
source	O
and	O
destination	O
are	O
supported	O
(	O
frequently	O
used	O
to	O
read/write	O
stack	B-Application
elements	O
addressed	O
using	O
small	O
immediate	O
offsets	O
)	O
.	O
</s>
<s>
Both	O
general	O
and	O
implicit	O
register	B-General_Concept
usage	O
;	O
although	O
all	O
seven	O
(	O
counting	O
ebp	O
)	O
general	O
registers	O
in	O
32-bit	O
mode	O
,	O
and	O
all	O
fifteen	O
(	O
counting	O
rbp	O
)	O
general	O
registers	O
in	O
64-bit	O
mode	O
,	O
can	O
be	O
freely	O
used	O
as	O
accumulators	B-General_Concept
or	O
for	O
addressing	O
,	O
most	O
of	O
them	O
are	O
also	O
implicitly	O
used	O
by	O
certain	O
(	O
more	O
or	O
less	O
)	O
special	O
instructions	O
;	O
affected	O
registers	O
must	O
therefore	O
be	O
temporarily	O
preserved	O
(	O
normally	O
stacked	O
)	O
,	O
if	O
active	O
during	O
such	O
instruction	O
sequences	O
.	O
</s>
<s>
Produces	O
conditional	O
flags	B-General_Concept
implicitly	O
through	O
most	O
integer	O
ALU	B-General_Concept
instructions	O
.	O
</s>
<s>
Supports	O
various	O
addressing	B-Language
modes	I-Language
including	O
immediate	O
,	O
offset	O
,	O
and	O
scaled	O
index	O
but	O
not	O
PC-relative	O
,	O
except	O
jumps	O
(	O
introduced	O
as	O
an	O
improvement	O
in	O
the	O
x86-64	B-Device
architecture	O
)	O
.	O
</s>
<s>
Includes	O
floating	B-Algorithm
point	I-Algorithm
to	O
a	O
stack	B-Application
of	O
registers	O
.	O
</s>
<s>
SIMD	B-Device
instructions	O
(	O
instructions	O
which	O
perform	O
parallel	O
simultaneous	O
single	O
instructions	O
on	O
many	O
operands	O
encoded	O
in	O
adjacent	O
cells	O
of	O
wider	O
registers	O
)	O
.	O
</s>
<s>
The	O
x86	B-Operating_System
architecture	I-Operating_System
has	O
hardware	O
support	O
for	O
an	O
execution	O
stack	B-Application
mechanism	O
.	O
</s>
<s>
Instructions	O
such	O
as	O
push	O
,	O
pop	O
,	O
call	O
and	O
ret	O
are	O
used	O
with	O
the	O
properly	O
set	O
up	O
stack	B-Application
to	O
pass	O
parameters	O
,	O
to	O
allocate	O
space	O
for	O
local	O
data	O
,	O
and	O
to	O
save	O
and	O
restore	O
call-return	O
points	O
.	O
</s>
<s>
The	O
ret	O
size	O
instruction	O
is	O
very	O
useful	O
for	O
implementing	O
space	O
efficient	O
(	O
and	O
fast	O
)	O
calling	O
conventions	O
where	O
the	O
callee	O
is	O
responsible	O
for	O
reclaiming	O
stack	B-Application
space	O
occupied	O
by	O
parameters	O
.	O
</s>
<s>
When	O
setting	O
up	O
a	O
stack	B-Application
frame	O
to	O
hold	O
local	O
data	O
of	O
a	O
recursive	O
procedure	O
there	O
are	O
several	O
choices	O
;	O
the	O
high	O
level	O
enter	O
instruction	O
(	O
introduced	O
with	O
the	O
80186	O
)	O
takes	O
a	O
procedure-nesting-depth	O
argument	O
as	O
well	O
as	O
a	O
local	O
size	O
argument	O
,	O
and	O
may	O
be	O
faster	O
than	O
more	O
explicit	O
manipulation	O
of	O
the	O
registers	O
(	O
such	O
as	O
push	O
bp	O
;	O
mov	O
bp	O
,	O
sp	O
;	O
sub	O
sp	O
,	O
size	O
)	O
.	O
</s>
<s>
Whether	O
it	O
is	O
faster	O
or	O
slower	O
depends	O
on	O
the	O
particular	O
x86-processor	O
implementation	O
as	O
well	O
as	O
the	O
calling	O
convention	O
used	O
by	O
the	O
compiler	B-Language
,	O
programmer	O
or	O
particular	O
program	O
code	O
;	O
most	O
x86	B-Operating_System
code	O
is	O
intended	O
to	O
run	O
on	O
x86-processors	O
from	O
several	O
manufacturers	O
and	O
on	O
different	O
technological	O
generations	O
of	O
processors	O
,	O
which	O
implies	O
highly	O
varying	O
microarchitectures	B-General_Concept
and	O
microcode	B-Device
solutions	O
as	O
well	O
as	O
varying	O
gate	O
-	O
and	O
transistor-level	O
design	O
choices	O
.	O
</s>
<s>
The	O
full	O
range	O
of	O
addressing	B-Language
modes	I-Language
(	O
including	O
immediate	O
and	O
base+offset	O
)	O
even	O
for	O
instructions	O
such	O
as	O
push	B-Application
and	I-Application
pop	I-Application
,	O
makes	O
direct	O
usage	O
of	O
the	B-Application
stack	I-Application
for	O
integer	O
,	O
floating	B-Algorithm
point	I-Algorithm
and	O
address	B-General_Concept
data	O
simple	O
,	O
as	O
well	O
as	O
keeping	O
the	O
ABI	B-Operating_System
specifications	O
and	O
mechanisms	O
relatively	O
simple	O
compared	O
to	O
some	O
RISC	O
architectures	O
(	O
require	O
more	O
explicit	O
call	O
stack	B-Application
details	O
)	O
.	O
</s>
<s>
x86	B-Language
assembly	I-Language
has	O
the	O
standard	O
mathematical	O
operations	O
,	O
add	O
,	O
sub	O
,	O
mul	O
,	O
with	O
idiv	O
;	O
the	O
logical	O
operators	O
and	O
,	O
or	O
,	O
xor	O
,	O
neg	O
;	O
bitshift	O
arithmetic	O
and	O
logical	O
,	O
sal/sar	O
,	O
shl/shr	O
;	O
rotate	O
with	O
and	O
without	O
carry	O
,	O
rcl/rcr	O
,	O
rol/ror	O
,	O
a	O
complement	O
of	O
BCD	O
arithmetic	O
instructions	O
,	O
aaa	O
,	O
aad	O
,	O
daa	O
and	O
others	O
.	O
</s>
<s>
x86	B-Language
assembly	I-Language
language	I-Language
includes	O
instructions	O
for	O
a	O
stack-based	O
floating-point	B-Algorithm
unit	O
(	O
FPU	O
)	O
.	O
</s>
<s>
The	O
FPU	O
was	O
an	O
optional	O
separate	O
coprocessor	O
for	O
the	O
8086	O
through	O
the	O
80386	B-General_Concept
,	O
it	O
was	O
an	O
on-chip	O
option	O
for	O
the	O
80486	O
series	O
,	O
and	O
it	O
is	O
a	O
standard	O
feature	O
in	O
every	O
Intel	B-Operating_System
x86	I-Operating_System
CPU	O
since	O
the	O
80486	O
,	O
starting	O
with	O
the	O
Pentium	O
.	O
</s>
<s>
The	O
operations	O
also	O
include	O
conversion	O
instructions	O
,	O
which	O
can	O
load	O
or	O
store	O
a	O
value	O
from	O
memory	O
in	O
any	O
of	O
the	O
following	O
formats	O
:	O
binary-coded	O
decimal	O
,	O
32-bit	O
integer	O
,	O
64-bit	O
integer	O
,	O
32-bit	O
floating-point	B-Algorithm
,	O
64-bit	O
floating-point	B-Algorithm
or	O
80-bit	O
floating-point	B-Algorithm
(	O
upon	O
loading	O
,	O
the	O
value	O
is	O
converted	O
to	O
the	O
currently	O
used	O
floating-point	B-Algorithm
mode	O
)	O
.	O
</s>
<s>
x86	B-Operating_System
also	O
includes	O
a	O
number	O
of	O
transcendental	O
functions	O
,	O
including	O
sine	O
,	O
cosine	O
,	O
tangent	O
,	O
arctangent	O
,	O
exponentiation	O
with	O
the	O
base	O
2	O
and	O
logarithms	O
to	O
bases	O
2	O
,	O
10	O
,	O
or	O
e	O
.	O
</s>
<s>
The	B-Application
stack	I-Application
register	B-General_Concept
to	O
stack	B-Application
register	B-General_Concept
format	O
of	O
the	O
instructions	O
is	O
usually	O
fop	O
st	O
,	O
st(n )	O
or	O
fop	O
st(n )	O
,	O
st	O
,	O
where	O
st	O
is	O
equivalent	O
to	O
st(0 )	O
,	O
and	O
st(n )	O
is	O
one	O
of	O
the	O
8	O
stack	B-Application
registers	O
(st(0 )	O
,	O
st(1 )	O
,	O
...	O
,	O
st(7 )	O
)	O
.	O
</s>
<s>
The	O
addition	O
,	O
subtraction	O
,	O
multiplication	O
,	O
division	O
,	O
store	O
and	O
comparison	O
instructions	O
include	O
instruction	O
modes	O
that	O
pop	O
the	O
top	O
of	O
the	B-Application
stack	I-Application
after	O
their	O
operation	O
is	O
complete	O
.	O
</s>
<s>
So	O
,	O
for	O
example	O
,	O
faddp	O
st(1 )	O
,	O
st	O
performs	O
the	O
calculation	O
st(1 )	O
=	O
st(1 )	O
+	O
st(0 )	O
,	O
then	O
removes	O
st(0 )	O
from	O
the	O
top	O
of	O
stack	B-Application
,	O
thus	O
making	O
what	O
was	O
the	O
result	O
in	O
st(1 )	O
the	O
top	O
of	O
the	B-Application
stack	I-Application
in	O
st(0 )	O
.	O
</s>
<s>
Modern	O
x86	B-Operating_System
CPUs	O
contain	O
SIMD	B-Device
instructions	O
,	O
which	O
largely	O
perform	O
the	O
same	O
operation	O
in	O
parallel	O
on	O
many	O
values	O
encoded	O
in	O
a	O
wide	O
SIMD	B-Device
register	B-General_Concept
.	O
</s>
<s>
Various	O
instruction	O
technologies	O
support	O
different	O
operations	O
on	O
different	O
register	B-General_Concept
sets	O
,	O
but	O
taken	O
as	O
complete	O
whole	O
(	O
from	O
MMX	B-Architecture
to	O
SSE4.2	O
)	O
they	O
include	O
general	O
computations	O
on	O
integer	O
or	O
floating-point	B-Algorithm
arithmetic	I-Algorithm
(	O
addition	O
,	O
subtraction	O
,	O
multiplication	O
,	O
shift	O
,	O
minimization	O
,	O
maximization	O
,	O
comparison	O
,	O
division	O
or	O
square	O
root	O
)	O
.	O
</s>
<s>
So	O
for	O
example	O
,	O
paddw	O
mm0	O
,	O
mm1	O
performs	O
4	O
parallel	O
16-bit	B-Device
(	O
indicated	O
by	O
the	O
w	O
)	O
integer	O
adds	O
(	O
indicated	O
by	O
the	O
padd	O
)	O
of	O
mm0	O
values	O
to	O
mm1	O
and	O
stores	O
the	O
result	O
in	O
mm0	O
.	O
</s>
<s>
Streaming	B-General_Concept
SIMD	I-General_Concept
Extensions	I-General_Concept
or	O
SSE	B-General_Concept
also	O
includes	O
a	O
floating-point	B-Algorithm
mode	O
in	O
which	O
only	O
the	O
very	O
first	O
value	O
of	O
the	O
registers	O
is	O
actually	O
modified	O
(	O
expanded	O
in	O
SSE2	B-General_Concept
)	O
.	O
</s>
<s>
Some	O
other	O
unusual	O
instructions	O
have	O
been	O
added	O
including	O
a	O
sum	B-Algorithm
of	I-Algorithm
absolute	I-Algorithm
differences	I-Algorithm
(	O
used	O
for	O
motion	O
estimation	O
in	O
video	O
compression	O
,	O
such	O
as	O
is	O
done	O
in	O
MPEG	O
)	O
and	O
a	O
16-bit	B-Device
multiply	O
accumulation	O
instruction	O
(	O
useful	O
for	O
software-based	O
alpha-blending	O
and	O
digital	O
filtering	O
)	O
.	O
</s>
<s>
SSE	B-General_Concept
(	O
since	O
SSE3	B-General_Concept
)	O
and	O
3DNow	B-General_Concept
!	I-General_Concept
</s>
<s>
extensions	O
include	O
addition	O
and	O
subtraction	O
instructions	O
for	O
treating	O
paired	O
floating-point	B-Algorithm
values	O
like	O
complex	O
numbers	O
.	O
</s>
<s>
In	O
addition	O
there	O
are	O
instructions	O
for	O
moving	O
data	O
between	O
the	O
integer	O
registers	O
and	O
XMM	O
(	O
used	O
in	O
SSE	B-General_Concept
)	O
/FPU	O
(	O
used	O
in	O
MMX	B-Architecture
)	O
registers	O
.	O
</s>
<s>
The	O
x86	B-Operating_System
processor	O
also	O
includes	O
complex	O
addressing	B-Language
modes	I-Language
for	O
addressing	O
memory	O
with	O
an	O
immediate	O
offset	O
,	O
a	O
register	B-General_Concept
,	O
a	O
register	B-General_Concept
with	O
an	O
offset	O
,	O
a	O
scaled	O
register	B-General_Concept
with	O
or	O
without	O
an	O
offset	O
,	O
and	O
a	O
register	B-General_Concept
with	O
an	O
optional	O
offset	O
and	O
another	O
scaled	O
register	B-General_Concept
.	O
</s>
<s>
So	O
for	O
example	O
,	O
one	O
can	O
encode	O
mov	O
eax	O
,	O
[	O
Table	O
+	O
ebx	O
+	O
esi*4 ]	O
as	O
a	O
single	O
instruction	O
which	O
loads	O
32	O
bits	O
of	O
data	O
from	O
the	O
address	B-General_Concept
computed	O
as	O
(	O
Table	O
+	O
ebx	O
+	O
esi	O
*	O
4	O
)	O
offset	O
from	O
the	O
ds	O
selector	O
,	O
and	O
stores	O
it	O
to	O
the	O
eax	O
register	B-General_Concept
.	O
</s>
<s>
In	O
general	O
x86	B-Operating_System
processors	O
can	O
load	O
and	O
use	O
memory	O
matched	O
to	O
the	O
size	O
of	O
any	O
register	B-General_Concept
it	O
is	O
operating	O
on	O
.	O
</s>
<s>
(	O
The	O
SIMD	B-Device
instructions	O
also	O
include	O
half-load	O
instructions	O
.	O
)	O
</s>
<s>
Most	O
2-operand	O
x86	B-Device
instructions	I-Device
,	O
including	O
integer	O
ALU	B-General_Concept
instructions	O
,	O
</s>
<s>
Many	O
32-bit	O
x86	B-Device
instructions	I-Device
also	O
have	O
a	O
SIB	O
addressing	B-Language
mode	I-Language
byte	O
that	O
follows	O
the	O
MOD-REG-R/M	O
byte	O
.	O
</s>
<s>
In	O
principle	O
,	O
because	O
the	O
instruction	B-Language
opcode	I-Language
is	O
separate	O
from	O
the	O
addressing	B-Language
mode	I-Language
byte	O
,	O
those	O
instructions	O
are	O
orthogonal	O
because	O
any	O
of	O
those	O
opcodes	B-Language
can	O
be	O
mixed-and-matched	O
with	O
any	O
addressing	B-Language
mode	I-Language
.	O
</s>
<s>
However	O
,	O
the	O
x86	B-Device
instruction	I-Device
set	I-Device
is	O
generally	O
considered	O
non-orthogonal	O
because	O
many	O
other	O
opcodes	B-Language
have	O
some	O
fixed	O
addressing	B-Language
mode	I-Language
(	O
they	O
have	O
no	O
addressing	B-Language
mode	I-Language
byte	O
)	O
,	O
and	O
every	O
register	B-General_Concept
is	O
special	O
.	O
</s>
<s>
The	O
x86	B-Device
instruction	I-Device
set	I-Device
includes	O
string	O
load	O
,	O
store	O
,	O
move	O
,	O
scan	O
and	O
compare	O
instructions	O
(	O
lods	O
,	O
stos	O
,	O
movs	O
,	O
scas	O
and	O
cmps	O
)	O
which	O
perform	O
each	O
operation	O
to	O
a	O
specified	O
size	O
(	O
b	O
for	O
8-bit	O
byte	O
,	O
w	O
for	O
16-bit	B-Device
word	O
,	O
d	O
for	O
32-bit	O
double	O
word	O
)	O
then	O
increments/decrements	O
(	O
depending	O
on	O
DF	O
,	O
direction	O
flag	O
)	O
the	O
implicit	O
address	B-General_Concept
register	I-General_Concept
(	O
si	O
for	O
lods	O
,	O
di	O
for	O
stos	O
and	O
scas	O
,	O
and	O
both	O
for	O
movs	O
and	O
cmps	O
)	O
.	O
</s>
<s>
For	O
the	O
load	O
,	O
store	O
and	O
scan	O
operations	O
,	O
the	O
implicit	O
target/source/comparison	O
register	B-General_Concept
is	O
in	O
the	O
al	O
,	O
ax	O
or	O
eax	O
register	B-General_Concept
(	O
depending	O
on	O
size	O
)	O
.	O
</s>
<s>
The	O
implicit	O
segment	B-Device
registers	I-Device
used	O
are	O
ds	O
for	O
si	O
and	O
es	O
for	O
di	O
.	O
</s>
<s>
The	O
cx	O
or	O
ecx	O
register	B-General_Concept
is	O
used	O
as	O
a	O
decrementing	O
counter	O
,	O
and	O
the	O
operation	O
stops	O
when	O
the	O
counter	O
reaches	O
zero	O
or	O
(	O
for	O
scans	O
and	O
comparisons	O
)	O
when	O
inequality	O
is	O
detected	O
.	O
</s>
<s>
The	B-Application
stack	I-Application
is	O
implemented	O
with	O
an	O
implicitly	O
decrementing	O
(	O
push	O
)	O
and	O
incrementing	O
(	O
pop	O
)	O
stack	B-Application
pointer	O
.	O
</s>
<s>
In	O
16-bit	B-Device
mode	O
,	O
this	O
implicit	O
stack	B-Application
pointer	O
is	O
addressed	O
as	O
SS:[SP],	O
in	O
32-bit	O
mode	O
it	O
is	O
SS:[ESP],	O
and	O
in	O
64-bit	O
mode	O
it	O
is	O
 [ RSP ] 	O
.	O
</s>
<s>
The	B-Application
stack	I-Application
pointer	O
actually	O
points	O
to	O
the	O
last	O
value	O
that	O
was	O
stored	O
,	O
under	O
the	O
assumption	O
that	O
its	O
size	O
will	O
match	O
the	O
operating	O
mode	O
of	O
the	O
processor	O
(	O
i.e.	O
,	O
16	O
,	O
32	O
,	O
or	O
64	O
bits	O
)	O
to	O
match	O
the	O
default	O
width	O
of	O
the	O
push/pop/call/ret	O
instructions	O
.	O
</s>
<s>
Also	O
included	O
are	O
the	O
instructions	O
enter	O
and	O
leave	O
which	O
reserve	O
and	O
remove	O
data	O
from	O
the	O
top	O
of	O
the	B-Application
stack	I-Application
while	O
setting	O
up	O
a	O
stack	B-Application
frame	O
pointer	O
in	O
bp/ebp/rbp	O
.	O
</s>
<s>
However	O
,	O
direct	O
setting	O
,	O
or	O
addition	O
and	O
subtraction	O
to	O
the	O
sp/esp/rsp	O
register	B-General_Concept
is	O
also	O
supported	O
,	O
so	O
the	O
enter/leave	O
instructions	O
are	O
generally	O
unnecessary	O
.	O
</s>
<s>
Other	O
instructions	O
for	O
manipulating	O
the	B-Application
stack	I-Application
include	O
pushf/popf	O
for	O
storing	O
and	O
retrieving	O
the	O
(	O
E	O
)	O
FLAGS	B-General_Concept
register	I-General_Concept
.	O
</s>
<s>
The	O
pusha/popa	O
instructions	O
will	O
store	O
and	O
retrieve	O
the	O
entire	O
integer	O
register	B-General_Concept
state	O
to	O
and	O
from	O
the	B-Application
stack	I-Application
.	O
</s>
<s>
Values	O
for	O
a	O
SIMD	B-Device
load	O
or	O
store	O
are	O
assumed	O
to	O
be	O
packed	O
in	O
adjacent	O
positions	O
for	O
the	O
SIMD	B-Device
register	B-General_Concept
and	O
will	O
align	O
them	O
in	O
sequential	O
little-endian	O
order	O
.	O
</s>
<s>
Some	O
SSE	B-General_Concept
load	O
and	O
store	O
instructions	O
require	O
16-byte	O
alignment	O
to	O
function	O
properly	O
.	O
</s>
<s>
The	O
SIMD	B-Device
instruction	O
sets	O
also	O
include	O
"	O
prefetch	O
"	O
instructions	O
which	O
perform	O
the	O
load	O
but	O
do	O
not	O
target	O
any	O
register	B-General_Concept
,	O
used	O
for	O
cache	O
loading	O
.	O
</s>
<s>
The	O
SSE	B-General_Concept
instruction	O
sets	O
also	O
include	O
non-temporal	O
store	O
instructions	O
which	O
will	O
perform	O
stores	O
straight	O
to	O
memory	O
without	O
performing	O
a	O
cache	O
allocate	O
if	O
the	O
destination	O
is	O
not	O
already	O
cached	O
(	O
otherwise	O
it	O
will	O
behave	O
like	O
a	O
regular	O
store	O
.	O
)	O
</s>
<s>
Most	O
generic	O
integer	O
and	O
floating-point	B-Algorithm
(	O
but	O
no	O
SIMD	B-Device
)	O
instructions	O
can	O
use	O
one	O
parameter	O
as	O
a	O
complex	O
address	B-General_Concept
as	O
the	O
second	O
source	O
parameter	O
.	O
</s>
<s>
The	O
x86	B-Language
assembly	I-Language
has	O
an	O
unconditional	O
jump	O
operation	O
,	O
jmp	B-Device
,	O
which	O
can	O
take	O
an	O
immediate	O
address	B-General_Concept
,	O
a	O
register	B-General_Concept
or	O
an	O
indirect	B-Language
address	I-Language
as	O
a	O
parameter	O
(	O
note	O
that	O
most	O
RISC	O
processors	O
only	O
support	O
a	O
link	O
register	B-General_Concept
or	O
short	O
immediate	O
displacement	O
for	O
jumping	O
)	O
.	O
</s>
<s>
These	O
conditional	O
operations	O
are	O
based	O
on	O
the	O
state	O
of	O
specific	O
bits	O
in	O
the	O
(	O
E	O
)	O
FLAGS	B-General_Concept
register	I-General_Concept
.	O
</s>
<s>
Many	O
arithmetic	O
and	O
logic	O
operations	O
set	O
,	O
clear	O
or	O
complement	O
these	O
flags	B-General_Concept
depending	O
on	O
their	O
result	O
.	O
</s>
<s>
The	O
comparison	O
cmp	O
(	O
compare	O
)	O
and	O
test	O
instructions	O
set	O
the	O
flags	B-General_Concept
as	O
if	O
they	O
had	O
performed	O
a	O
subtraction	O
or	O
a	O
bitwise	O
AND	O
operation	O
,	O
respectively	O
,	O
without	O
altering	O
the	O
values	O
of	O
the	O
operands	O
.	O
</s>
<s>
There	O
are	O
also	O
instructions	O
such	O
as	O
clc	O
(	O
clear	O
carry	O
flag	O
)	O
and	O
cmc	O
(	O
complement	O
carry	O
flag	O
)	O
which	O
work	O
on	O
the	O
flags	B-General_Concept
directly	O
.	O
</s>
<s>
Floating	B-Algorithm
point	I-Algorithm
comparisons	O
are	O
performed	O
via	O
fcom	O
or	O
ficom	O
instructions	O
which	O
eventually	O
have	O
to	O
be	O
converted	O
to	O
integer	O
flags	B-General_Concept
.	O
</s>
<s>
A	O
short	O
jump	O
uses	O
an	O
8-bit	O
signed	O
operand	O
,	O
which	O
is	O
a	O
relative	O
offset	O
from	O
the	O
current	B-General_Concept
instruction	I-General_Concept
.	O
</s>
<s>
A	O
near	O
jump	O
is	O
similar	O
to	O
a	O
short	O
jump	O
but	O
uses	O
a	O
16-bit	B-Device
signed	O
operand	O
(	O
in	O
real	B-Application
or	O
protected	B-Application
mode	I-Application
)	O
or	O
a	O
32-bit	O
signed	O
operand	O
(	O
in	O
32-bit	O
protected	B-Application
mode	I-Application
only	O
)	O
.	O
</s>
<s>
A	O
far	O
jump	O
is	O
one	O
that	O
uses	O
the	O
full	O
segment	O
base:offset	O
value	O
as	O
an	O
absolute	O
address	B-General_Concept
.	O
</s>
<s>
Before	O
transferring	O
control	O
to	O
the	O
subroutine	O
,	O
call	O
pushes	O
the	O
segment	O
offset	O
address	B-General_Concept
of	O
the	O
instruction	O
following	O
the	O
call	O
onto	O
the	B-Application
stack	I-Application
;	O
ret	O
pops	O
this	O
value	O
off	O
the	B-Application
stack	I-Application
,	O
and	O
jumps	O
to	O
it	O
,	O
effectively	O
returning	O
the	O
flow	O
of	O
control	O
to	O
that	O
part	O
of	O
the	O
program	O
.	O
</s>
<s>
There	O
are	O
also	O
two	O
similar	O
instructions	O
,	O
int	B-Device
(	O
interrupt	B-Application
)	O
,	O
which	O
saves	O
the	O
current	O
(	O
E	O
)	O
FLAGS	B-General_Concept
register	I-General_Concept
value	O
on	O
the	B-Application
stack	I-Application
,	O
then	O
performs	O
a	O
far	O
call	O
,	O
except	O
that	O
instead	O
of	O
an	O
address	B-General_Concept
,	O
it	O
uses	O
an	O
interrupt	B-Application
vector	O
,	O
an	O
index	O
into	O
a	O
table	O
of	O
interrupt	B-Application
handler	O
addresses	B-General_Concept
.	O
</s>
<s>
Typically	O
,	O
the	O
interrupt	B-Application
handler	O
saves	O
all	O
other	O
CPU	B-General_Concept
registers	I-General_Concept
it	O
uses	O
,	O
unless	O
they	O
are	O
used	O
to	O
return	O
the	O
result	O
of	O
an	O
operation	O
to	O
the	O
calling	O
program	O
(	O
in	O
software	O
called	O
interrupts	B-Application
)	O
.	O
</s>
<s>
The	O
matching	O
return	O
from	O
interrupt	B-Application
instruction	O
is	O
iret	O
,	O
which	O
restores	O
the	O
flags	B-General_Concept
after	O
returning	O
.	O
</s>
<s>
Soft	O
Interrupts	B-Application
of	O
the	O
type	O
described	O
above	O
are	O
used	O
by	O
some	O
operating	B-General_Concept
systems	I-General_Concept
for	O
system	B-Operating_System
calls	I-Operating_System
,	O
and	O
can	O
also	O
be	O
used	O
in	O
debugging	O
hard	O
interrupt	B-Application
handlers	O
.	O
</s>
<s>
Hard	O
interrupts	B-Application
are	O
triggered	O
by	O
external	O
hardware	O
events	O
,	O
and	O
must	O
preserve	O
all	O
register	B-General_Concept
values	O
as	O
the	O
state	O
of	O
the	O
currently	O
executing	O
program	O
is	O
unknown	O
.	O
</s>
<s>
In	O
Protected	B-Application
Mode	I-Application
,	O
interrupts	B-Application
may	O
be	O
set	O
up	O
by	O
the	O
OS	O
to	O
trigger	O
a	O
task	O
switch	O
,	O
which	O
will	O
automatically	O
save	O
all	O
registers	O
of	O
the	O
active	O
task	O
.	O
</s>
<s>
Using	O
interrupt	B-Application
21h	O
for	O
output	O
–	O
other	O
samples	O
use	O
libc	B-Language
's	O
printf	O
to	O
print	O
to	O
stdout	O
.	O
</s>
<s>
Running	O
it	O
under	O
strace	O
verifies	O
that	O
no	O
extra	O
system	B-Operating_System
calls	I-Operating_System
are	O
made	O
in	O
the	O
process	O
.	O
</s>
<s>
The	O
printf	O
version	O
would	O
make	O
many	O
more	O
system	B-Operating_System
calls	I-Operating_System
to	O
initialize	O
libc	B-Language
and	O
do	O
dynamic	B-Application
linking	I-Application
.	O
</s>
<s>
Flags	B-General_Concept
are	O
heavily	O
used	O
for	O
comparisons	O
in	O
the	O
x86	B-Operating_System
architecture	I-Operating_System
.	O
</s>
<s>
When	O
a	O
comparison	O
is	O
made	O
between	O
two	O
data	O
,	O
the	O
CPU	O
sets	O
the	O
relevant	O
flag	O
or	O
flags	B-General_Concept
.	O
</s>
<s>
Following	O
this	O
,	O
conditional	O
jump	O
instructions	O
can	O
be	O
used	O
to	O
check	O
the	O
flags	B-General_Concept
and	O
branch	O
to	O
code	O
that	O
should	O
run	O
,	O
e.g.	O
</s>
<s>
Flags	B-General_Concept
are	O
also	O
used	O
in	O
the	O
x86	B-Operating_System
architecture	I-Operating_System
to	O
turn	O
on	O
and	O
off	O
certain	O
features	O
or	O
execution	O
modes	O
.	O
</s>
<s>
For	O
example	O
,	O
to	O
disable	O
all	O
maskable	B-Application
interrupts	I-Application
,	O
you	O
can	O
use	O
the	O
instruction	O
:	O
</s>
<s>
The	O
flags	B-General_Concept
register	I-General_Concept
can	O
also	O
be	O
directly	O
accessed	O
.	O
</s>
<s>
The	O
low	O
8	O
bits	O
of	O
the	O
flag	O
register	B-General_Concept
can	O
be	O
loaded	O
into	O
ah	O
using	O
the	O
lahf	O
instruction	O
.	O
</s>
<s>
The	O
entire	O
flags	B-General_Concept
register	I-General_Concept
can	O
also	O
be	O
moved	O
on	O
and	O
off	O
the	B-Application
stack	I-Application
using	O
the	O
instructions	O
pushf	O
,	O
popf	O
,	O
int	B-Device
(	O
including	O
into	O
)	O
and	O
iret	O
.	O
</s>
<s>
The	O
instruction	B-General_Concept
pointer	I-General_Concept
is	O
called	O
ip	O
in	O
16-bit	B-Device
mode	O
,	O
eip	O
in	O
32-bit	O
mode	O
,	O
and	O
rip	O
in	O
64-bit	O
mode	O
.	O
</s>
<s>
The	O
instruction	B-General_Concept
pointer	I-General_Concept
register	I-General_Concept
points	O
to	O
the	O
memory	B-General_Concept
address	I-General_Concept
which	O
the	O
processor	O
will	O
next	O
attempt	O
to	O
execute	O
;	O
it	O
cannot	O
be	O
directly	O
accessed	O
in	O
16-bit	B-Device
or	O
32-bit	O
mode	O
,	O
but	O
a	O
sequence	O
like	O
the	O
following	O
can	O
be	O
written	O
to	O
put	O
the	O
address	B-General_Concept
of	O
next_line	O
into	O
eax	O
:	O
</s>
<s>
This	O
sequence	O
of	O
instructions	O
generates	O
position-independent	B-Operating_System
code	I-Operating_System
because	O
call	O
takes	O
an	O
instruction-pointer-relative	O
immediate	O
operand	O
describing	O
the	O
offset	O
in	O
bytes	O
of	O
the	O
target	O
instruction	O
from	O
the	O
next	B-General_Concept
instruction	I-General_Concept
(	O
in	O
this	O
case	O
0	O
)	O
.	O
</s>
<s>
Writing	O
to	O
the	O
instruction	B-General_Concept
pointer	I-General_Concept
is	O
simple	O
—	O
a	O
jmp	B-Device
instruction	O
sets	O
the	O
instruction	B-General_Concept
pointer	I-General_Concept
to	O
the	O
target	O
address	B-General_Concept
,	O
so	O
,	O
for	O
example	O
,	O
a	O
sequence	O
like	O
the	O
following	O
will	O
put	O
the	O
contents	O
of	O
eax	O
into	O
eip	O
:	O
</s>
<s>
In	O
64-bit	O
mode	O
,	O
instructions	O
can	O
reference	O
data	O
relative	O
to	O
the	O
instruction	B-General_Concept
pointer	I-General_Concept
,	O
so	O
there	O
is	O
less	O
need	O
to	O
copy	O
the	O
value	O
of	O
the	O
instruction	B-General_Concept
pointer	I-General_Concept
to	O
another	O
register	B-General_Concept
.	O
</s>
