<s>
The	O
Intel	B-Device
BCD	I-Device
opcodes	I-Device
are	O
a	O
set	O
of	O
six	O
x86	B-Operating_System
instructions	O
that	O
operate	O
with	O
binary-coded	O
decimal	B-Application
numbers	O
.	O
</s>
<s>
The	O
radix	O
used	O
for	O
the	O
representation	O
of	O
numbers	O
in	O
the	O
x86	B-Operating_System
processors	O
is	O
2	O
.	O
</s>
<s>
However	O
,	O
the	O
x86	B-Operating_System
processors	O
do	O
have	O
limited	O
support	O
for	O
the	O
decimal	B-Application
numeral	I-Application
system	I-Application
.	O
</s>
<s>
In	O
addition	O
,	O
the	O
x87	B-Application
part	O
supports	O
a	O
unique	O
18-digit	O
(	O
ten-byte	O
)	O
BCD	O
format	O
that	O
can	O
be	O
loaded	O
into	O
and	O
stored	O
from	O
the	O
floating	B-Algorithm
point	I-Algorithm
registers	O
,	O
from	O
where	O
ordinary	O
FP	O
computations	O
can	O
be	O
performed	O
.	O
</s>
<s>
The	O
integer	O
BCD	O
instructions	O
are	O
no	O
longer	O
supported	O
in	O
long	B-Application
mode	I-Application
.	O
</s>
<s>
BCD	O
numbers	O
can	O
be	O
represented	O
in	O
two	O
ways	O
in	O
integer	O
registers	O
:	O
packed	O
decimal	B-Application
and	O
unpacked	O
decimal	B-Application
.	O
</s>
<s>
In	O
packed	O
decimal	B-Application
representation	O
a	O
decimal	B-Application
digit	O
is	O
stored	O
in	O
one	O
nibble	O
.	O
</s>
<s>
In	O
unpacked	O
decimal	B-Application
representation	O
a	O
decimal	B-Application
digit	O
is	O
stored	O
in	O
one	O
byte	B-Application
.	O
</s>
<s>
BCD	O
numbers	O
are	O
generally	O
assumed	O
to	O
be	O
stored	O
in	O
the	O
lowest	O
byte	B-Application
of	O
a	O
register	O
,	O
e.g.	O
</s>
<s>
AL	O
;	O
operations	O
on	O
unpacked	O
BCD	O
numbers	O
expect	O
the	O
least	O
significant	O
digit	O
in	O
the	O
lowest	O
byte	B-Application
of	O
a	O
register	O
,	O
e.g.	O
</s>
<s>
AL	O
,	O
and	O
the	O
most	O
significant	O
digit	O
in	O
the	O
second	O
lowest	O
byte	B-Application
,	O
e.g.	O
</s>
<s>
Only	O
the	O
decimal	B-Application
numbers	O
0	O
to	O
99	O
can	O
be	O
added	O
directly	O
.	O
</s>
<s>
First	O
the	O
numbers	O
are	O
added	O
as	O
usual	O
using	O
add	O
(	O
or	O
adc	O
if	O
you	O
need	O
the	O
carry	B-Algorithm
flag	I-Algorithm
)	O
.	O
</s>
<s>
The	O
processor	B-General_Concept
will	O
set	O
the	O
adjust	O
flag	O
if	O
the	O
sum	O
of	O
both	O
lower	O
nibbles	O
is	O
16	O
or	O
higher	O
,	O
and	O
the	O
carry	B-Algorithm
flag	I-Algorithm
if	O
the	O
sum	O
of	O
both	O
bytes	B-Application
is	O
256	O
or	O
higher	O
.	O
</s>
<s>
The	O
result	O
is	O
adjusted	O
using	O
daa	O
(	O
decimal	B-Application
adjust	O
after	O
addition	O
)	O
:	O
If	O
the	O
least	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
or	O
if	O
the	O
adjust	O
flag	O
is	O
set	O
,	O
then	O
the	O
processor	B-General_Concept
adds	O
6	O
to	O
the	O
result	O
and	O
discards	O
any	O
overflow	O
of	O
the	O
nibble	O
.	O
</s>
<s>
Then	O
,	O
if	O
the	O
most	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
or	O
if	O
the	O
carry	B-Algorithm
flag	I-Algorithm
is	O
set	O
,	O
then	O
the	O
processor	B-General_Concept
adds	O
96	O
(	O
6	O
times	O
16	O
)	O
to	O
the	O
result	O
and	O
sets	O
the	O
carry	B-Algorithm
flag	I-Algorithm
.	O
</s>
<s>
The	O
result	O
is	O
adjusted	O
using	O
aaa	O
(	O
ASCII	O
adjust	O
after	O
addition	O
)	O
:	O
If	O
the	O
least	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
then	O
the	O
processor	B-General_Concept
adds	O
6	O
to	O
it	O
and	O
discards	O
any	O
overflow	O
of	O
the	O
nibble	O
,	O
and	O
stores	O
it	O
in	O
the	O
least	O
significant	O
byte	B-Application
.	O
</s>
<s>
The	O
most	O
significant	O
byte	B-Application
is	O
incremented	O
.	O
</s>
<s>
Note	O
that	O
at	O
this	O
point	O
the	O
most	O
significant	O
byte	B-Application
may	O
not	O
contain	O
a	O
valid	O
decimal	B-Application
number	O
.	O
</s>
<s>
Only	O
the	O
decimal	B-Application
numbers	O
0	O
to	O
99	O
can	O
be	O
subtracted	O
directly	O
.	O
</s>
<s>
First	O
the	O
numbers	O
are	O
subtracted	O
as	O
usual	O
using	O
sub	O
(	O
or	O
sbb	O
if	O
you	O
need	O
the	O
carry	B-Algorithm
flag	I-Algorithm
)	O
.	O
</s>
<s>
The	O
processor	B-General_Concept
will	O
set	O
the	O
adjust	O
flag	O
if	O
a	O
borrow	O
occurred	O
in	O
the	O
least	O
significant	O
nibble	O
,	O
and	O
the	O
carry	B-Algorithm
flag	I-Algorithm
if	O
a	O
borrow	O
occurred	O
in	O
the	O
most	O
significant	O
nibble	O
.	O
</s>
<s>
The	O
result	O
is	O
adjusted	O
using	O
das	O
(	O
decimal	B-Application
adjust	O
after	O
subtraction	O
)	O
:	O
If	O
the	O
least	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
or	O
if	O
the	O
adjust	O
flag	O
is	O
set	O
,	O
then	O
the	O
processor	B-General_Concept
subtracts	O
6	O
from	O
the	O
result	O
.	O
</s>
<s>
Then	O
,	O
if	O
the	O
most	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
or	O
if	O
the	O
carry	B-Algorithm
flag	I-Algorithm
is	O
set	O
,	O
then	O
the	O
processor	B-General_Concept
subtracts	O
96	O
(	O
6	O
times	O
16	O
)	O
from	O
the	O
result	O
and	O
sets	O
the	O
carry	B-Algorithm
flag	I-Algorithm
.	O
</s>
<s>
The	O
result	O
is	O
adjusted	O
using	O
aas	O
(	O
ASCII	O
adjust	O
after	O
subtraction	O
)	O
:	O
If	O
the	O
least	O
significant	O
nibble	O
of	O
the	O
result	O
is	O
10	O
or	O
higher	O
,	O
then	O
the	O
processor	B-General_Concept
subtracts	O
6	O
from	O
it	O
and	O
stores	O
it	O
in	O
the	O
least	O
significant	O
byte	B-Application
.	O
</s>
<s>
The	O
most	O
significant	O
byte	B-Application
is	O
decremented	O
.	O
</s>
<s>
Note	O
that	O
at	O
this	O
point	O
the	O
most	O
significant	O
byte	B-Application
may	O
not	O
contain	O
a	O
valid	O
decimal	B-Application
number	O
.	O
</s>
<s>
Then	O
the	O
result	O
is	O
adjusted	O
using	O
aam	O
(	O
ASCII	O
adjust	O
for	O
multiplication	O
)	O
:	O
The	O
processor	B-General_Concept
divides	O
the	O
result	O
by	O
ten	O
,	O
storing	O
the	O
quotient	O
(	O
just	O
the	O
integral	O
part	O
)	O
in	O
the	O
most	O
significant	O
byte	B-Application
of	O
the	O
result	O
and	O
the	O
remainder	O
in	O
the	O
least	O
significant	O
byte	B-Application
of	O
the	O
result	O
.	O
</s>
<s>
First	O
the	O
operands	O
are	O
converted	O
to	O
normal	O
binary	O
representation	O
using	O
aad	O
(	O
ASCII	O
adjust	O
before	O
division	O
)	O
:	O
The	O
processor	B-General_Concept
converts	O
numbers	O
by	O
multiplying	O
the	O
most	O
significant	O
byte	B-Application
by	O
10	O
and	O
adding	O
the	O
least	O
significant	O
byte	B-Application
.	O
</s>
<s>
The	O
x87	B-Application
coprocessor	O
has	O
BCD	O
support	O
in	O
the	O
form	O
of	O
a	O
pair	O
of	O
load	O
(	O
FBLD	O
)	O
and	O
store-and-pop	O
(	O
FBSTP	O
)	O
instructions	O
.	O
</s>
<s>
The	O
former	O
loads	O
a	O
80-bit	O
BCD	O
integer	O
into	O
the	O
FPU	B-General_Concept
,	O
while	O
the	O
latter	O
writes	O
a	O
FPU	B-General_Concept
value	O
as	O
a	O
80-bit	O
integer	O
value	O
into	O
the	O
memory	O
.	O
</s>
<s>
Inside	O
of	O
the	O
FPU	B-General_Concept
,	O
the	O
values	O
are	O
stored	O
as	O
normal	O
x87	B-Application
extended-precision	O
floats	B-Algorithm
.	O
</s>
<s>
Unlike	O
the	O
integer-facing	O
versions	O
,	O
the	O
two	O
instructions	O
remain	O
available	O
in	O
long	B-Application
mode	I-Application
.	O
</s>
<s>
Binary-coded	O
decimal	B-Application
(	O
BCD	O
)	O
numbers	O
are	O
used	O
for	O
storing	O
decimal	B-Application
numbers	O
,	O
especially	O
in	O
financial	O
software	O
.	O
</s>
<s>
The	O
opcodes	B-Language
mentioned	O
above	O
give	O
the	O
x86	B-Operating_System
rudimentary	O
BCD	O
support	O
.	O
</s>
<s>
Adding	O
BCD	O
numbers	O
using	O
these	O
opcodes	B-Language
is	O
a	O
complex	O
task	O
,	O
and	O
requires	O
many	O
instructions	O
to	O
add	O
even	O
modest	O
numbers	O
.	O
</s>
<s>
On	O
an	O
x86	B-Operating_System
processor	B-General_Concept
,	O
calculations	O
with	O
binary	O
numbers	O
are	O
usually	O
a	O
lot	O
faster	O
than	O
the	O
same	O
calculations	O
with	O
BCD	O
numbers	O
.	O
</s>
