Defines a Union-TypeName that represents an aggregate data type containing one or more fields. All of the fields occupy the same physical position in storage.
Syntax
Union-Name UNION FieldDeclaration . . . Union-Name ENDS
Where FieldDeclaration has the following form:
[FieldName] Allocation-TypeName InitialValue [, InitialValue ...]Remarks
This directive is not available in M510 mode.
The syntax for the FieldDeclaration is that of a normal data allocation statement. See the section on Data Allocation for a full description of this syntax.
The various parts of the FieldDeclaration are described as follows:
FieldName
.386 IS_sint32 equ -4 IS_sint16 equ -2 IS_sint8 equ -1 NO_TYPE equ 0 IS_uint8 equ 1 IS_uint16 equ 2 IS_uint32 equ 4 TYPE_T typedef SBYTE DATA_T union uint8 BYTE ? sint8 SBYTE ? uint16 WORD ? sint16 SWORD ? uint32 DWORD ? sint32 SDWORD ? DATA_T ends VALUE_T struct DataType TYPE_T NO_TYPE DataValue DATA_T {} VALUE_T ends .data Value VALUE_T { IS_uint8, { 1 } } ; unsigned 8-bit value of 1 .code ; Procedure: IsNegative ; Returns : 1 in EAX if Value.DataValue holds a negative number ; 0 in EAX if Value.DataValue holds a positive number IsNegative proc cmp Value.DataType, NO_TYPE ; check sign of TYPE_T jns short Positive ; if positive, so is value ; check for signed 8-bit integer cmp Value.DataType, IS_sint8 jne short @F ; not 8, check for 16 movsx EAX, Value.DataValue.sint8 ; convert 8 bits to 32 jmp short Check ; and check the value ; check for signed 16-bit integer @@: cmp Value.DataType, IS_sint16 jne short @F ; not 16, check for 32 movsx EAX, Value.DataValue.sint16 ; convert 16 bits to 32 jmp short Check ; and check the value ; check for signed 32-bit integer @@: cmp Value.DataType, IS_sint32 jne short Positive ; unknown, assume positive mov EAX, Value.DataValue.sint32 ; get full 32 bit number Check: or EAX,EAX ; check for negative value jns short Positive ; no sign bit, positive mov EAX, 1 ; indicate negative ret ; and return Positive: mov EAX, 0 ; indicate positive ret ; and return IsNegative endp end