0.1.3 Data Types

MASM 6.0 introduces an entirely new concept of data typing for assembly language. This section summarizes new and changed features relating to data declarations in MASM 6.0.

Defining Typed Variables

You can now use the type names as directives to define variables. Initializers are unsigned by default. The following are equivalent:

var1 DB 25

var1 BYTE 25

Signed Types

You can use the new SBYTE, SWORD, and SDWORD directives to declare signed data. See Section 4.1.1, “Allocating Memory for Integer Variables.”

Floating-Point Types

MASM 6.0 also introduces new directives for declaring floating-point variables, REAL4, REAL8, and REAL10. See Section 6.1.1, “Declaring Floating-Point Variables and Constants,” for information on these new type directives.

Qualified Types

MASM 6.0 allows type definitions to include distance and language type attributes. Procedures, procedure prototypes, and external declarations allow the type to be specified as a qualified type. Section 1.2.6, “Data Types,” gives a complete description of qualified types.

Structures

Structures have changed in several ways:

Structures can be nested.

The names of structure fields need not be unique. As a result, references to field names must be qualified.

Initialization of structure variables can continue over multiple lines as long as the final noncomment character in the line is a comma.

Curly braces and angle brackets are equivalent.

For example, this code works in MASM 6.0:

SCORE STRUCT

team1 BYTE 10 DUP (?)

score1 BYTE ?

team2 BYTE 10 DUP (?)

score2 BYTE ?

SCORE ENDS

first SCORE {"BEARS", 20, ; This comment is allowed.

"CUBS", 10 }

mov al, [bx].score.team1 ; Field name must be qualified

; with structure name.

You can use OPTION OLDSTRUCTS or OPTION M510 to enable MASM 5.1 behavior for structures. See Section A.2, “Compatibility between MASM 5.1 and 6.0.” For more information on structures and unions, see Section 5.2.

Unions

MASM 6.0 allows the definition of unions. Unions differ from structures in that all field initializers occupy the same data space. The new UNION directive defines these variables. For more information, see Section 5.2, “Structures and Unions.”

Types Defined with TYPEDEF

The new TYPEDEF directive defines a type for use later in the program. It is most useful for defining pointer types. For more information, see Sections 1.2.6, “Data Types,” and 3.3.1, “Defining Pointer Types with TYPEDEF.”

Names of Identifiers

The names of identifiers in MASM 6.0 can be up to 247 characters long, and all the characters are significant. In previous versions of MASM (or if OPTION M510 is enabled), names are significant to 31 characters only. For more information on identifiers, see Section 1.2.2, “Identifiers.” For more information on the OPTION directive, see Section 1.3.2, “Using the OPTION Directive.”

Multiple-Line Initializers

In MASM 6.0, a comma at the end of a line implies that the line continues. For example, the following code is legal in MASM 6.0:

longstring BYTE "This string ",

"continues over two lines."

bitmasks BYTE 80h, 40h, 20h, 10h,

08h, 04h, 02h, 01h

For more information, see Section 1.2.8, “Statements.”

Comments in Extended Lines

Earlier versions of MASM allow a backslash (\) as the line-continuation character if it is the last nonspace character in the line. MASM 6.0 permits a comment to follow the backslash.

Determining Size and Length of Data Labels

The new LENGTHOF operator returns the number of data items allocated for a data label. MASM 6.0 also has a new SIZEOF operator. When applied to a type, the SIZEOF operator returns the size attribute of the type expression. When applied to a data label, SIZEOF returns the number of bytes used by the initializer in the label's definition. In this case, SIZEOF for a variable equals the number of bytes in the type multiplied by LENGTHOF for the variable.

The LENGTH and SIZE operators have been retained for backward compatibility. See “Length and Size of Labels with OPTION M510” in Section A.2.2 for the behavior of SIZE under OPTION M510, and see “LENGTH Operator Applied to Record Types” in Section A.2.1.2 for obsolete behavior with the LENGTH operator.

For information on LENGTHOF and SIZEOF, see Section 5.1.1, “Declaring and Referencing Arrays,” Section 5.1.2, “Declaring and Initializing Strings,” Section 5.2.1, “Declaring Structure and Union Variables,” and Section 5.3.2, “Defining Record Variables.”

HIGHWORD and LOWWORD Operators

These new operators return the high and low words for the 32-bit operand given. They are similar to the HIGH and LOW operators of MASM 5.1 except that HIGHWORD and LOWWORD can take only constants as operands, not relocatables (labels).

PTR and CodeView

In MASM 5.1, the PTR operator, when applied to a data initializer, specifies what information should be generated by CodeView.

Semantically using PTR in this manner is still valid, but this does not affect CodeView typing. Defining pointers with the TYPEDEF directive allows CodeView to generate correct information. See Section 3.3.1, “Defining Pointer Types with TYPEDEF.”