= Sign language compilation directives

Equals directive (equal-sign directive) to a symbolic name with an integer expression linking the following syntax:

 

name = expression

Typically, expression is a 32-bit integer value. When the compiled program in the assembler preprocessing stage, all occurrences are replaced with the name expression. Assuming the following statement appears in place of a source code file begins:

COUNT = 500

Then, assuming the following statement at a position subsequent line 10:

mov eax, COUNT

Then, when the assembler file, MASM scans the source file, and generates the corresponding line of code:

mov eax, 500

Why sign?

Programmers can completely skip COUNT symbol, simplified to the direct use of MOV instruction to write constants 500, but experience has shown that if a sign will make the program easier to read and maintain.

Imagine, if COUNT appears several times throughout the program, then, after a time, programmers can easily redefine its value:

COUNT = 600

If re-compile the source file, all have COUNT will be automatically replaced by 600.

Current address counter

One of the most important symbols is called the current address counter (current location counter), expressed as a $. For example, the following statement declares a variable selfPtr, offset and initialize variables for:

selfPtr DWORD $

Keyboard definition

It is generally defined program symbols used to identify the numeric keypad code. For example, 27 is the ASCII code Esc key:

Esc_key = 27

In the back of the program, if the statement using this symbol instead of an integer constant, then it will have a stronger self-descriptive.

Use
mov al, Esc_key; good programming style
instead of
mov al, 27; bad programming style

DUP operator using

"Data Definition" section describes how to use DUP operator to store strings and arrays. In order to simplify maintenance procedures, the use of counter DUP should be symbols counter.

In the following example, if you have defined COUNT, then it can be used in the following data definitions:

array dword COUNT DUP(0)

redefine

With the symbol "=" definition, can be redefined in the same program. The following example shows the changes when the COUNT values, assembler how to calculate its value:

COUNT = 5
mov al,COUNT ; AL = 5
COUNT = 10
mov al,COUNT ; AL = 10
COUNT = 100
mov al,COUNT ; AL = 100

Changing the sign of the value, e.g. COUNT, the statement does not affect the order of execution at run time. In contrast, in the assembler preprocessing stage, the order of the source symbols are processed to change the value according to the assembler.

Next: calculating the length of the array and string

Highly recommended reading articles

40 + annual salary of big data development [W] tutorial, all here!

Guess you like

Origin blog.csdn.net/Javaxuxuexi/article/details/93312847