6.1.1 Declaring Floating-Point Variables and Constants

You can allocate real constants using the REAL4, REAL8, and REAL10 directives. The list below shows the size of the floating-point number each of these directives allocates.

Directive Size

REAL4 Short (32-bit) real numbers
REAL8 Long (64-bit) real numbers
REAL10 10-byte (80-bit) real numbers and BCD numbers

The possible ranges for floating-point variables are given in Table 6.1.

Table 6.1 Ranges of Floating-Point Variables


Data Type

Bits
Significant Digits
Approximate Range

Short real 32 6–7 ±1.18 x 10-38 to ±3.40 x 1038
Long real 64 15–16 ±2.23 x 10-308 to ±1.79 x 10308
10-byte real 80 19 ±3.37 x 10-4932 to ±1.18 x 104932

With previous versions of MASM, the DD, DQ, and DT directives could be used to allocate real constants. These directives are still supported by MASM 6.0, but this means that the variables are integers rather than floating-point values. Although this makes no difference in the assembly code, CodeView displays the values incorrectly.

Summary: There are two forms for specifying floating-point numbers.

You can specify floating-point constants either as decimal constants or as encoded hexadecimal constants. You can express decimal real-number constants in the form

[[+ | –]] integer.[[fraction]][[E]][[[[+ | –]]exponent]]

For example, the numbers 2.523E1 and -3.6E-2 are written in the correct decimal format. These numbers can be used as initializers for real-number variables.

Digits of real numbers are always evaluated as base 10. During assembly, the assembler converts real-number constants given in decimal format to a binary format. The sign, exponent, and mantissa of the real number are encoded as bit fields within the number.

You can also specify the encoded format directly with hexadecimal digits (0–9 plus A–F). The number must begin with a decimal digit (0–9) and a leading zero if necessary, and end with the real-number designator (R). It cannot be signed.

For example, the hexadecimal number 3F800000r can be used as an initializer for a doubleword-sized variable.

The maximum range of exponent values and the number of digits required in the hexadecimal number depend on the directive. The number of digits for encoded numbers used with REAL4, REAL8, and REAL10 must be 8, 16, and 20 digits, respectively. If the number has a leading zero, the number must be 9, 17, or 21 digits.

Examples of decimal constant and hexadecimal specifications are shown here:

; Real numbers

short REAL4 25.23 ; IEEE format

double REAL8 2.523E1 ; IEEE format

tenbyte REAL10 2523.0E-2 ; 10-byte real format

; Encoded as hexadecimals

ieeeshort REAL4 3F800000r ; 1.0 as IEEE short

ieeedouble REAL8 3FF0000000000000r ; 1.0 as IEEE long

temporary REAL10 3FFF8000000000000000r ; 1.0 as 10-byte

; real

Section 6.1.2, “Storing Numbers in Floating-Point Format,” explains the IEEE formats––the way the assembler actually stores the data.

Pascal or C programmers may prefer to create language-specific TYPEDEF declarations, as illustrated in this example:

; C-language specific

float TYPEDEF REAL4

double TYPEDEF REAL8

long_double TYPEDEF REAL10

; Pascal-language specific

SINGLE TYPEDEF REAL4

DOUBLE TYPEDEF REAL8

EXTENDED TYPEDEF REAL10

For applications of TYPEDEF other than aliasing, see Section 3.3.1, “Defining Pointer Types with TYPEDEF.”