Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
system prog new.docx
Скачиваний:
0
Добавлен:
01.05.2025
Размер:
275.7 Кб
Скачать

38. Macrodefinitions. Blocks of repetitions. Macrooperators.

A macro is a gro of repetitive instructions in a program which are codified only once and can be used as many times as necessary.

The main difference between a macro and a procedure is that in the macro the passage of parameters is possible and in the procedure it is not, this is only applicable for the TASM - there are other programming languages which do allow it. At the moment the macro is executed each parameter is substituted by the name or value specified at the time of the call.

We can say then that a procedure is an extension of a determined program, while the macro is a module with specific functions which can be used by different programs.

Another difference between a macro and a procedure is the way of calling each one, to call a procedure the use of a directive is required, on the other hand the call of macros is done as if it were an assembler instruction.

Syntax of a Macro

The parts which make a macro are:

Declaration of the macro Code of the macro Macro termination directive

The declaration of the macro is done the following way:

NameMacro MACRO [parameter1, parameter2...]

Even though we have the functionality of the parameters it is possible to create a macro which does not need them.

The directive for the termination of the macro is: ENDM

To use a macro it is only necessary to call it by its name, as if it were another assembler instruction, since directives are no longer necessary as in the case of the procedures.

Blocks repetitions

The simplest block repetitions REPT (not supported WASM) performs assembling portion of the program specified number of times. For example, if you want to create a byte array initialized values ​​from 0 to 0FFh, this can be done by repeating the DB pseudo-command, as follows:

hexnumber = 0

hextable label byte; name of the array

               rept 256, Block start

               db hexnumber; These two lines are assembled

hexnumber = hexnumber +1; 256.

               endm

Blocks of repetitions, as well as macros can be called with parameters. For this purpose, the directive IRP and IRPC:

               irp parameter <value1, value2 ...>

                 ...

               endm

               irpc parameter string

                 ...

               endm

Block described the directive IRP, will be called as many times as indicated in the list of values ​​(in angle brackets), and each iteration will be determined by a label with the name of the parameter that is equal to the next value from the list. For example, the next block of repetitions will keep the stack registers AX, BX, CX and DX:

               irp reg, <ax,bx,cx,dx>

               push reg

               endm

Directive IRPC (FORC in WASM) describes a block that is executed as many times as symbols the specified string, and each iteration will be determined by a label with the name of the parameter that is equal to the next character in the string. If the string contains spaces or other characters that are not allowed for the labels, it must be enclosed in angle brackets. For example, the next block is the string in memory, after placing each character in the string attribute 0Fh (white on black background), so that this line can then be copied directly into the video memory.

               irpc character, <character string>

               db '& character &', 0Fh

               endm In this example, the ampersands that option instead of the character had been substituted its value even inside the quotation marks. Ampersand is one of the macro statement - the special operators that act only within the macro blocks and repetitions.

The macro statements or Macrooperators. The macro statements ampersand (&) is needed to ensure that the parameter that is passed as an operand of macro definitions or block repetitions, substitute value before processing line assembler. For example, the following macro will execute the command PUSH EAX, when called as PUSHREG A:  pushreg macro letter             push e & letter & x             endm  Sometimes it is possible to use only one ampersand at the beginning of the parameter if there is no ambiguity. For example, if the number is transmitted, and the need to create a set of variables with names ending this number:             irp number, <1,2,3,4>             number db?             endm  Macro statement <> (angle brackets) operates so that all the text in the parentheses is treated as a text string, even if it contains spaces or other separators. As we have seen, this macro statement is used to transfer text strings as parameters to the macro. Another frequent use of angle brackets - Transfer list of options embedded macro definitions or block repetitions.  Macro statement! (Exclamation mark) is used similarly to the angle brackets, but only works in one the next character, so if that character is a comma - or angle bracket, it will still be sent as part of a macro parameter.  Macro statement% (percentage) points out that being followed by the text of an expression and must be calculated. This is usually required in order to pass as a parameter to the macro not the expression itself, and its result. 

Соседние файлы в предмете [НЕСОРТИРОВАННОЕ]