<s>
In	O
computer	B-General_Concept
programming	I-General_Concept
,	O
an	O
inline	B-Language
assembler	I-Language
is	O
a	O
feature	O
of	O
some	O
compilers	B-Language
that	O
allows	O
low-level	O
code	O
written	O
in	O
assembly	B-Language
language	I-Language
to	O
be	O
embedded	O
within	O
a	O
program	O
,	O
among	O
code	O
that	O
otherwise	O
has	O
been	O
compiled	B-Language
from	O
a	O
higher-level	B-Language
language	I-Language
such	O
as	O
C	B-Language
or	O
Ada	B-Language
.	O
</s>
<s>
The	O
embedding	O
of	O
assembly	B-Language
language	I-Language
code	O
is	O
usually	O
done	O
for	O
one	O
of	O
these	O
reasons	O
:	O
</s>
<s>
Optimization	O
:	O
Programmers	O
can	O
use	O
assembly	B-Language
language	I-Language
code	O
to	O
implement	O
the	O
most	O
performance-sensitive	O
parts	O
of	O
their	O
program	O
's	O
algorithms	O
,	O
code	O
that	O
is	O
apt	O
to	O
be	O
more	O
efficient	O
than	O
what	O
might	O
otherwise	O
be	O
generated	O
by	O
the	O
compiler	B-Language
.	O
</s>
<s>
Access	O
to	O
processor	O
specific	O
instructions	O
:	O
Most	O
processors	O
offer	O
special	O
instructions	O
,	O
such	O
as	O
Compare	B-Operating_System
and	I-Operating_System
Swap	I-Operating_System
and	O
Test	B-Operating_System
and	I-Operating_System
Set	I-Operating_System
instructions	O
which	O
may	O
be	O
used	O
to	O
construct	O
semaphores	B-Operating_System
or	O
other	O
synchronization	O
and	O
locking	O
primitives	O
.	O
</s>
<s>
Nearly	O
every	O
modern	O
processor	O
has	O
these	O
or	O
similar	O
instructions	O
,	O
as	O
they	O
are	O
necessary	O
to	O
implement	O
multitasking	B-Operating_System
.	O
</s>
<s>
Examples	O
of	O
specialized	O
instructions	O
are	O
found	O
in	O
the	O
SPARC	B-Architecture
VIS	B-General_Concept
,	O
Intel	O
MMX	B-Architecture
and	O
SSE	B-General_Concept
,	O
and	O
Motorola	O
Altivec	B-General_Concept
instruction	B-General_Concept
sets	I-General_Concept
.	O
</s>
<s>
Access	O
to	O
special	O
calling	O
conventions	O
not	O
yet	O
supported	O
by	O
the	O
compiler	B-Language
.	O
</s>
<s>
System	B-Operating_System
calls	I-Operating_System
and	O
interrupts	B-Application
:	O
High-level	B-Language
languages	I-Language
rarely	O
have	O
a	O
direct	O
facility	O
to	O
make	O
arbitrary	O
system	B-Operating_System
calls	I-Operating_System
,	O
so	O
assembly	B-Language
code	I-Language
is	O
used	O
.	O
</s>
<s>
Direct	O
interrupts	B-Application
are	O
even	O
more	O
rarely	O
supplied	O
.	O
</s>
<s>
To	O
emit	O
special	O
directives	O
for	O
the	O
linker	O
or	O
assembler	B-Language
,	O
for	O
example	O
to	O
change	O
sectioning	O
,	O
macros	O
,	O
or	O
to	O
make	O
symbol	O
aliases	O
.	O
</s>
<s>
On	O
the	O
other	O
hand	O
,	O
inline	B-Language
assembler	I-Language
poses	O
a	O
direct	O
problem	O
for	O
the	O
compiler	B-Language
itself	O
as	O
it	O
complicates	O
the	O
analysis	O
of	O
what	O
is	O
done	O
to	O
each	O
variable	O
,	O
a	O
key	O
part	O
of	O
register	O
allocation	O
.	O
</s>
<s>
Inline	B-Language
assembler	I-Language
also	O
complicates	O
future	O
porting	O
and	O
maintenance	O
of	O
a	O
program	O
.	O
</s>
<s>
Alternative	O
facilities	O
are	O
often	O
provided	O
as	O
a	O
way	O
to	O
simplify	O
the	O
work	O
for	O
both	O
the	O
compiler	B-Language
and	O
the	O
programmer	O
.	O
</s>
<s>
Intrinsic	B-Application
functions	I-Application
for	O
special	O
instructions	O
are	O
provided	O
by	O
most	O
compilers	B-Language
and	O
C-function	O
wrappers	O
for	O
arbitrary	O
system	B-Operating_System
calls	I-Operating_System
are	O
available	O
on	O
every	O
Unix	B-Application
platform	O
.	O
</s>
<s>
The	O
ISO	O
C++	O
standard	O
and	O
ISO	O
C	B-Language
standards	O
(	O
annex	O
J	O
)	O
specify	O
a	O
conditionally	O
supported	O
syntax	O
for	O
inline	B-Language
assembler	I-Language
:	O
</s>
<s>
This	O
definition	O
,	O
however	O
,	O
is	O
rarely	O
used	O
in	O
actual	O
C	B-Language
,	O
as	O
it	O
is	O
simultaneously	O
too	O
liberal	O
(	O
in	O
the	O
interpretation	O
)	O
and	O
too	O
restricted	O
(	O
in	O
the	O
use	O
of	O
one	O
string	O
literal	O
only	O
)	O
.	O
</s>
<s>
In	O
practical	O
use	O
,	O
inline	B-Language
assembly	I-Language
operating	O
on	O
values	O
is	O
rarely	O
standalone	O
as	O
free-floating	O
code	O
.	O
</s>
<s>
Since	O
the	O
programmer	O
cannot	O
predict	O
what	O
register	O
a	O
variable	O
is	O
assigned	O
to	O
,	O
compilers	B-Language
typically	O
provide	O
a	O
way	O
to	O
substitute	O
them	O
in	O
as	O
an	O
extension	O
.	O
</s>
<s>
There	O
are	O
,	O
in	O
general	O
,	O
two	O
types	O
of	O
inline	B-Language
assembly	I-Language
supported	O
by	O
C/C	O
++	O
compilers	B-Language
:	O
</s>
<s>
(	O
or	O
)	O
in	O
GCC	B-Application
.	O
</s>
<s>
GCC	B-Application
uses	O
a	O
direct	O
extension	O
of	O
the	O
ISO	O
rules	O
:	O
assembly	B-Language
code	I-Language
template	O
is	O
written	O
in	O
strings	O
,	O
with	O
inputs	O
,	O
outputs	O
,	O
and	O
clobbered	O
registers	O
specified	O
after	O
the	O
strings	O
in	O
colons	O
.	O
</s>
<s>
C	B-Language
variables	O
are	O
used	O
directly	O
while	O
register	O
names	O
are	O
quoted	O
as	O
string	O
literals	O
.	O
</s>
<s>
in	O
Microsoft	B-Application
Visual	I-Application
C++	I-Application
(	O
MSVC	B-Application
)	O
,	O
Borland/Embarcadero	O
C	B-Language
compiler	B-Language
,	O
and	O
descendents	O
.	O
</s>
<s>
This	O
syntax	O
is	O
not	O
based	O
on	O
ISO	O
rules	O
at	O
all	O
;	O
programmers	O
simply	O
write	O
ASM	O
inside	O
a	O
block	O
without	O
needing	O
to	O
conform	O
to	O
C	B-Language
syntax	O
.	O
</s>
<s>
Variables	O
are	O
available	O
as	O
if	O
they	O
are	O
registers	O
and	O
some	O
C	B-Language
expressions	O
are	O
allowed	O
.	O
</s>
<s>
ARM	O
Compiler	B-Language
used	O
to	O
have	O
a	O
similar	O
facility	O
.	O
</s>
<s>
The	O
two	O
families	O
of	O
extensions	O
represent	O
different	O
understandings	O
of	O
division	O
of	O
labor	O
in	O
processing	O
inline	B-Language
assembly	I-Language
.	O
</s>
<s>
The	O
GCC	B-Application
form	O
preserves	O
the	O
overall	O
syntax	O
of	O
the	O
language	O
and	O
compartmentizes	O
what	O
the	O
compiler	B-Language
needs	O
to	O
know	O
:	O
what	O
is	O
needed	O
and	O
what	O
is	O
changed	O
.	O
</s>
<s>
It	O
does	O
not	O
explicitly	O
require	O
the	O
compiler	B-Language
to	O
understand	O
instruction	O
names	O
,	O
as	O
the	O
compiler	B-Language
is	O
only	O
needed	O
to	O
substitute	O
its	O
register	O
assignments	O
,	O
plus	O
a	O
few	O
operations	O
,	O
to	O
handle	O
the	O
input	O
requirements	O
.	O
</s>
<s>
The	O
MSVC	B-Application
form	O
of	O
an	O
embedded	O
domain-specific	B-Language
language	I-Language
provides	O
ease	O
of	O
writing	O
,	O
but	O
it	O
requires	O
the	O
compiler	B-Language
itself	O
to	O
know	O
about	O
opcode	O
names	O
and	O
their	O
clobbering	O
properties	O
,	O
demanding	O
extra	O
attention	O
in	O
maintenance	O
and	O
porting	O
.	O
</s>
<s>
It	O
is	O
still	O
possible	O
to	O
check	O
GCC-style	O
assembly	O
for	O
clobber	O
mistakes	O
with	O
knowledge	O
of	O
the	O
instruction	B-General_Concept
set	I-General_Concept
.	O
</s>
<s>
GNAT	O
(	O
Ada	B-Language
language	I-Language
frontend	O
of	O
the	O
GCC	B-Application
suite	O
)	O
,	O
and	O
LLVM	B-Application
uses	O
the	O
GCC	B-Application
syntax	O
.	O
</s>
<s>
The	O
D	B-Application
programming	I-Application
language	I-Application
uses	O
a	O
DSL	O
similar	O
to	O
the	O
MSVC	B-Application
extension	O
officially	O
for	O
x86_64	O
,	O
but	O
the	O
LLVM-based	O
LDC	O
also	O
provides	O
the	O
GCC-style	O
syntax	O
on	O
every	O
architecture	O
.	O
</s>
<s>
MSVC	B-Application
only	O
supports	O
inline	B-Language
assembler	I-Language
on	O
32-bit	O
x86	B-Operating_System
.	O
</s>
<s>
The	O
Rust	O
language	O
has	O
since	O
migrated	O
to	O
a	O
syntax	O
abstracting	O
away	O
inline	B-Language
assembly	I-Language
options	O
further	O
than	O
the	O
LLVM	B-Application
(	O
GCC-style	O
)	O
version	O
.	O
</s>
<s>
The	O
OS	O
runs	O
at	O
a	O
more	O
privileged	O
level	O
(	O
kernel	O
mode	O
)	O
than	O
the	O
user	O
(	O
user	O
mode	O
)	O
;	O
a	O
(	O
software	O
)	O
interrupt	B-Application
is	O
used	O
to	O
make	O
requests	O
to	O
the	O
operating	O
system	O
.	O
</s>
<s>
This	O
is	O
rarely	O
a	O
feature	O
in	O
a	O
higher-level	B-Language
language	I-Language
,	O
and	O
so	O
wrapper	O
functions	O
for	O
system	B-Operating_System
calls	I-Operating_System
are	O
written	O
using	O
inline	B-Language
assembler	I-Language
.	O
</s>
<s>
The	O
following	O
C	B-Language
code	O
example	O
shows	O
an	O
x86	B-Operating_System
system	B-Operating_System
call	I-Operating_System
wrapper	O
in	O
AT&T	O
assembler	B-Language
syntax	O
,	O
using	O
the	O
GNU	B-Application
Assembler	I-Application
.	O
</s>
<s>
In	O
this	O
particular	O
case	O
,	O
the	O
wrapper	O
performs	O
a	O
system	B-Operating_System
call	I-Operating_System
of	O
a	O
number	O
given	O
by	O
the	O
caller	O
with	O
three	O
operands	O
,	O
returning	O
the	O
result	O
.	O
</s>
<s>
To	O
recap	O
,	O
GCC	B-Application
supports	O
both	O
basic	O
and	O
extended	O
assembly	O
.	O
</s>
<s>
The	O
former	O
simply	O
passes	O
text	O
verbatim	O
to	O
the	O
assembler	B-Language
,	O
while	O
the	O
latter	O
performs	O
some	O
substitutions	O
for	O
register	O
locations	O
.	O
</s>
<s>
This	O
example	O
of	O
inline	B-Language
assembly	I-Language
from	O
the	O
D	B-Application
programming	I-Application
language	I-Application
shows	O
code	O
that	O
computes	O
the	O
tangent	O
of	O
x	O
using	O
the	O
x86	B-Operating_System
's	O
FPU	B-General_Concept
(	O
x87	B-Application
)	O
instructions	O
.	O
</s>
<s>
For	O
readers	O
unfamiliar	O
with	O
x87	B-Application
programming	O
,	O
the	O
followed	O
by	O
conditional	O
jump	O
idiom	O
is	O
used	O
to	O
access	O
the	O
x87	B-Application
FPU	I-Application
status	O
word	O
bits	O
C0	O
and	O
C2	O
.	O
</s>
<s>
stores	O
the	O
status	O
in	O
a	O
general-purpose	O
register	O
;	O
sahf	O
sets	O
the	O
FLAGS	B-General_Concept
register	I-General_Concept
to	O
the	O
higher	O
8	O
bits	O
of	O
the	O
register	O
;	O
and	O
the	O
jump	O
is	O
used	O
to	O
judge	O
on	O
whatever	O
flag	O
bit	O
that	O
happens	O
to	O
correspond	O
to	O
the	O
FPU	B-General_Concept
status	O
bit	O
.	O
</s>
