| ||
Unions are similar to structures. They also consist of individual records. However, there is one significant difference: The length of the union instance in memory is equal to the length of its longest field. All fields will start with the same address the one, in which the union will start. The sense of a union is that the same memory area can be considered in the context of the same data type.
An example of a union appears as follows :
EXTCHAR UNION ascii DB ? extascii DW ? EXTCHAR ENDS
This union is an extended definition of the ASCII code. To use a union in your program, it is necessary to define the union in a way similar to defining structures.
; In data segment easc EXTCHAR <0>
Now, you will have a 2-byte structure. Access to the entire word is carried out through the extascii field: MOV easc.extascii , AX . Access to the least significant byte of the word is through the ascii field: MOV easc.ascii , AL .
| ||