|
|
||
|
|
||
|
|
||
The STRUC directive allows you to join several dissimilar data values of different types. These data items are called structure fields. First, it is necessary to define the structure template using the STRUC keyword; then, using the < > directive, it is possible to define any number of structures. Consider the following example:
STRUC COMPLEX
RE DD ?
IM DD ?
STRUC ENDS
...
; In data segment
COMP1 COMPLEX <?>
COMP2 COMPLEX <0>
; Initialization by zero
Access to the structure fields is carried out by reference points, for example, MOV COMP1.RE , EAX .
| Note |
For working with string constants, MASM32 and TASM32 provide a large set of string macros: CATSTR , INSTR , and so on. However, we are not going to practice macro programming in Assembly language, therefore, we won' t consider these possibilities. |
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
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
An example of a union appears as
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 .
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
There is one convenient method of working with structures and unions that
COMPLEX STRUC
RE DD ?
IM DD ?
COMPLEX ENDS
.
.
.
; In data segment
COMP COMPLEX <0>
; In code segment
MOV EBX, OFFSET COMP
ASSUME EBX:PTR C0MPLEX
MOV [EBX].RE, 10
MOV [EBX].IM, 10
ASSUME EBX:NOTHING
Actually, the MOV [EBX] .RE , 10 command is equivalent to MOV DWORD PTR [EBX] , 10 , and the MOV [EBX].IM , 10 command is equivalent to MOV DWORD PTR [EBX+4] , 10 . You likely will agree that this is very convenient.
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
Conditional assembling provides the possibility of bypassing specific program
IF expression ... ENDIF
IF expression ... ELSE ... ENDIF
IF expression 1 ... ELSEIF expression 2 ... ELSEIF expression 3 ... ELSE ... ENDIF
The expression is
MASM and TASM support several special-purpose directives for conditional assembling.
IFE expression ... ELSEIFE ... ENDIFE
The IF1 and IF2 operators check the first and the second pass of assembling.
The
IFDEF
operator checks whether a symbolic
There are other types of IF operators. The required information can be found in any reference on Assembly language.
There is the large set of directives starting with .ERR . For example, .ERRE will cause the assembling process stop and will display an error message if the condition takes the value 0.
Conditional assembling will be used in the end of this chapter to write the example program that can be translated using both MASM and TASM.
|
|
||
|
|
||
|
|
||