Intel 64 and IA-32 Architectures Software Developers Manual Volume 1, Basic Architecture
Vol. 1 4-13
DATA TYPES
4.7 BCD AND PACKED BCD INTEGERS
Binary-coded decimal integers (BCD integers) are unsigned 4-bit integers with valid
values ranging from 0 to 9. IA-32 architecture defines operations on BCD integers
located in one or more general-purpose registers or in one or more x87 FPU registers
(see Figure 4-9).
When operating on BCD integers in general-purpose registers, the BCD values can be
unpacked (one BCD digit per byte) or packed (two BCD digits per byte). The value of
an unpacked BCD integer is the binary value of the low half-byte (bits 0 through 3).
The high half-byte (bits 4 through 7) can be any value during addition and subtrac-
tion, but must be zero during multiplication and division. Packed BCD integers allow
two BCD digits to be contained in one byte. Here, the digit in the high half-byte is
more significant than the digit in the low half-byte.
When operating on BCD integers in x87 FPU data registers, BCD values are packed in
an 80-bit format and referred to as decimal integers. In this format, the first 9 bytes
hold 18 BCD digits, 2 digits per byte. The least-significant digit is contained in the
lower half-byte of byte 0 and the most-significant digit is contained in the upper half-
byte of byte 9. The most significant bit of byte 10 contains the sign bit (0 = positive
and 1 = negative; bits 0 through 6 of byte 10 are don’t care bits). Negative decimal
integers are not stored in two's complement form; they are distinguished from posi-
tive decimal integers only by the sign bit. The range of decimal integers that can be
encoded in this format is
–10
18
+ 1 to 10
18
– 1.
The decimal integer format exists in memory only. When a decimal integer is loaded
in an x87 FPU data register, it is automatically converted to the double-extended-
precision floating-point format. All decimal integers are exactly representable in
double extended-precision format.
Table 4-4 gives the possible encodings of value in the decimal integer data type.
Figure 4-9. BCD Data Types
Packed BCD Integers
BCDBCD
0
BCD Integers
7
BCDX
34
0
80-Bit Packed BCD Decimal Integers
79
D0
4 Bits = 1 BCD Digit
Sign
D1D2D3D4D5
D6
D7D8D9D10D11D12D13D14D15D16D17
78 7271
X
0734