
Chapter 3: General-Purpose Programming
43
24593—Rev. 3.09—September 2003
AMD 64-Bit Technology
Binary-Coded-Decimal (BCD) Digits.
BCD digits have values ranging
from 0 to 9. These values can be represented in binary encoding
with four bits. For example, 0000b represents the decimal
number 0 and 1001b represents the decimal number 9. Values
ranging from 1010b to 1111b are invalid for this data type.
Because a byte contains eight bits, two BCD digits can be stored
in a single byte. This is referred to as
packed-BCD
. If a single
BCD digit is stored per byte, it is referred to as
unpacked-BCD
.
In the x87 floating-point programming environment (described
in Section 6, “x87 Floating-Point Programming,” on page 285)
an 80-bit packed BCD data type is also supported, along with
conversions between floating-point and BCD data types, so that
data expressed in the BCD format can be operated on as
floating-point values.
Integer add, subtract, multiply, and divide instructions can be
used to operate on single (unpacked) BCD digits. The result
must be adjusted to produce a correct BCD representation. For
unpacked BCD numbers, the ASCII-adjust instructions are
provided to simplify that correction. In the case of division, the
adjustment must be made prior to executing the integer-divide
instruction.
Similarly, integer add and subtract instructions can be used to
operate on packed-BCD digits. The result must be adjusted to
produce a correct packed-BCD representation. Decimal-adjust
Table 3-2.
Representable Values of General-Purpose Data Types
Data Type
Byte
Word
Doubleword
Quadword
Double
Quadword
2
Signed Integers
1
-2
7
to +(2
7
-1)
-2
15
to +(2
15
-1)
-2
31
to +(2
31
-1)
-2
63
to +(2
63
-1)
-2
127
to +(2
127
-1)
Unsigned Integers
0 to +2
8
-1
(0 to 255)
0 to +2
16
-1
(0 to 65,535)
0 to +2
32
-1
(0 to 4.29 x 10
9
)
0 to +2
64
-1
(0 to 1.84 x 10
19
)
0 to +2
128
-1
(0 to 3.40 x 10
38
)
Packed BCD Digits
00 to 99
multiple packed BCD-digit bytes
BCD Digit
0 to 9
multiple BCD-digit bytes
Note:
1. The sign bit is the most-significant bit (e.g., bit 7 for a byte, bit 15 for a word, etc.).
2. The double quadword data type is supported in the RDX:RAX registers by the MUL, IMUL, DIV, IDIV, and CQO instructions.