Macro assessment

Synonym MASM General Refers to the Macro Programming

Compilation and Assembler

The source program written in assembly language needs to be translated into a target program to be executed by the machine. This translation process is called compilation, and the program to complete the assembly task is called assembler, see Figure 1.

assembler is the earliest is also the most mature system software. In addition to being able to translate the assembly language source program into a machine language program, it is also possible to automatically allocate storage areas (including program area, data area, temporary area, etc.) according to the user's requirements; automatically put various kinds of carry system The number conversion is converted into a binary, convert the character to the ASCII code, calculate the value of the expression; the automatic source program checks, gives an error message (such as illegal format, undefined museum, lasers, missing operands, etc. )Wait. Assembler with these functions is also called basic assembly (or small assembly ASM).

macro programming sequence

Based on the basic compilation, it is further allowed to define a command sequence as a macro assembly (MASM) in the source program. program. It contains all ASM functions, but also high-level assembly language features such as macro, structure, records.

The main feature of macro assembly is to increase macro processing in the assembler. It allows users to easily define and use macros, which can be used in multiple appearances in the program, with a certain format, and can be modulated by a minority adjustment of program paragraphs. This method not only reduces the length of the program, increase readability, and the format of the program paragraph needs to change, only must change the definition, without having to change each usage.

Macro assembly includes not only the functionality of the general assembler, but also the data structure used by the advanced program is an assembler close to the advanced program. For example, it provides a record, structure, and string operation; there are many functions such as macro processing, conditional assembly, and disk operating system DOS function calls; the development of the program and the debugging means are also relatively complete.

Reasons for the use of macro assembly

During the compilation language program, some function segments need to be repeated multiple times, alone is just the number of operands. In order to reduce the workload of programming, two methods are usually used:

(1) to write the program segment as a separate subroutine;

(2) defines the block into a macro.

Macro (instruction)

(1) shorten the source code;

(2) expand instruction set;

(3 Change the meaning of certain instruction assistance (the priority of the macro is higher than the instructions and directives).

macro

macro is a wide existing concept in computer software systems. From office software office to program development language C, etc., you can define a process to be operated as a macro. Specifically, in assembly language, macro is also one of the main features of compilation, which is another simplified source of simplified source procedures similar to the subroutine.

Programming language, macro is a program code with independent features in the source program, and the macro can also be called a macro, macro operation. The use of macros requires three steps: macro definition, macro adjustment, and macro. First macro definition; then macro call; finally, the Macro extension is made by MASM during assembly.

macro definition

macro definition statement Macro and subroutine definition statement proc is a pseudo-instruction. Macro definition requires a pair of pseudo-instructions Macro and ENDM completion. The macro defined format is as follows:

macro name Macro [dummy 1, dummy 2, ...]

...

Squiry Stroke

...

endm

Description: The macro definition does not generate a target code, just uses the connection between "macro name" and a source code. Among them, dumns 1, dummy 2, ... are virtual parameters or form parameters, separated by commas. Valves or shape is not set.

For example: Define keyboard input macro Input:

input macro

MOV AH, 01H

int 21 h

Macro assessment

endm

should be noted that when you name, don't be the same as the instruction name of the assembly language, the word is the same.

macro call

When using a macro in the program, just write the macro name [inform]. The format of the macro is: macro name [Real parametric 1, Real parametric 2, ..., Real Parts n].

For example, enter a character from the keyboard, determine if it is a "one" number, not, continue to input, is end. (Using the previously defined macro).

model small

stack 100h

code

start:

input

CMP Al, '-' <

RetSys

end start

macro display open

macro display Replace the macro's program segment target code for macro bodies in macro definitions. When assembled sources, macro assessment will macro the macro of each macro, replace the corresponding shape, and change the macro bodies. Figure 2 is an example of a macro deployment.

Common Macro Processing Pseudo Directive

Macro Definition Pseudo Directive (Macro / Endm)

Format:

Macro Macro < / p>

(macro)

endm

MacRo is a macro definition, which defines a macro name as a block included in the macro definition body. ENDM represents the end of the macro, and there is no macro name in front. Once a macro definition, you can use the macro name multiple times. But you must define first, then call. Macro definition allows nested, that is, macro definitions can contain another macro definition, and macro modulus can also be used, but it must be defined first, then call.

Declaration of the directive (local)

LOCAL in the macro body is to declare a partial reference number in the macro body to avoid the same reference numeral in the source program when macro extension There are many incorrections that appear multiple times to generate a multiple-definition of labeling. The LOCAL directive must be located before all other statements (including comments) in the macroblock, its format is:

local Local ID [, ...]

, for example, the following macro completion to complete the register One hexadecimal number is converted to the corresponding ASCII code. Since the local label appears in the macro body, the local label in the macro body must be declared using the LOCAL directive.

HEXTOASC Macro REG

Local Num

Cmp REG, 0AH

JC Num

Add Reg, 07h

Num: add reg, 30h

endm

Clear macro defined for instructions (PURGE)

macro name can be Other variable names, labels, instructions, pseudo-operated names in the program, the highest priority of the macro, which is the highest level of the macro, so that the directive or pseudo operation of the same name is invalid. In order to restore the function of these instructions or pseudo instructions, obey the definition of machine instructions, macro assembler provides pseudo-operation Purge to cancel macro definitions when appropriate.

The general format of the Purge directive is:

Purge macro defined name [, ...]

square bracket indicates that Purge can cancel multiple macro definitions, The macro name is separated by a comma. Such as macro definition:

Sub Macro VARX, VARY, Result

...

endm

macro call: SUB X, Y , Z

Purge Sub

"purge sub" Sub recovery subtraction function.

Related Articles
TOP