User Guide

38 General-Purpose Programming
AMD64 Technology 24592—Rev. 3.15—November 2009
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 237) 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 instructions
are provided to simplify packed-BCD result corrections.
Strings. Strings are a continuous sequence of a single data type. The string instructions can be used to
operate on byte, word, doubleword, or quadword data types. The maximum length of a string of any
data type is 2
32
–1 bytes, in legacy or compatibility modes, or 2
64
–1 bytes in 64-bit mode. One of the
more common types of strings used by applications are byte data-type strings known as ASCII strings,
which can be used to represent character data.
Bit strings are also supported by instructions that operate specifically on bit strings. In general, bit
strings can start and end at any bit location within any byte, although the BTx bit-string instructions
assume that strings start on a byte boundary. The length of a bit string can range in size from a single
bit up to 2
32
–1 bits, in legacy or compatibility modes, or 2
64
-–1 bits in 64-bit mode.
Unsigned Integers
0to+2
8
-1
(0 to 255)
0to+2
16
-1
(0 to 65,535)
0to+2
32
-1
(0 to 4.29 x 10
9
)
0to+2
64
-1
(0 to 1.84 x 10
19
)
0to+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
Table 3-2. Representable Values of General-Purpose Data Types (continued)
Data Type Byte Word Doubleword Quadword
Double
Quadword
2
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.