Home | | Microprocessors and Microcontrollers | Macros - 8086 Microprocessor

Chapter: Microprocessor and Microcontroller : 8086 Microprocessor

Macros - 8086 Microprocessor

Macros is needed for providing the programming ease of a procedure while avoiding the linkage.

Macros

Disadvantages of Procedure

1. Linkage associated with them.

 

2.  It sometimes requires more code to program the linkage than is needed to perform the task. If this is the case, a procedure may not save memory and execution time is considerably increased.

3. Macros is needed for providing the programming ease of a procedure while avoiding the linkage. Macro is a segment of code that needs to be written only once but whose basic structure can be caused to be repeated several times within a source module by placing a single statement at the point of each reference.

 

A macro is unlike a procedure in that the machine instructions are repeated each time the macro is referenced. Therefore, no memory is saved, but programming time is conserved (no linkage is required) and some degree of modularity is achieved. The code that is to be repeated is called the prototype code. The prototype code along with the statements for referencing and terminating is called the macro definition.

 

Once a macro is defined, it can be inserted at various points in the program by using macro calls. When a macro call is encountered by the assembler, the assembler replaces the

 

call with the macro code. Insertion of the macro code by the assembler for a macro call is referred to as a macro expansion. In order to allow the prototype code to be used in a variety of situations, macro definition and the prototype code can use dummy parameters which can be replaced by the actual parameters when the macro is expanded. During a macro expansion, the first actual parameter replaces the first dummy parameter in the prototype code, the second actual parameter replaces the second dummy parameter, and so on.

A macro call has the form

 

%Macro name (Actual parameter list) with the actual parameters being separated by commas.

 

%MULTIPLY (CX, VAR, XYZ[BX]

Local Labels

 

Consider a macro called ABSOL which makes use of labels. This macro is used to replace the operand by its absolute value.

 

%*DEFINE (ABSOL(OPER)) ( CMP %OPER, 0

 

JGE NEXT

NEG %OPER

%NEXT: NOP)

 

When the macro ABSOL is called for the first time, the label NEXT will appear in the program and, therefore it becomes defined. Any subsequent call will cause NEXT to be redefined. This will result in an error during assembly process because NEXT has been associated with more than one location. One solution to this problem would be to have NEXT replaced by a dummy parameter for the label. This would require the programmer to keep track of dummy parameters used.

 

One solution to this problem is the use of Local Labels. Local labels are special labels that will have suffixes that get incremented each time the macros are called. These suffixes are two digit numbers that gets incremented by one starting from zero. Labels can be declared as local label by attaching a prefix Local. Local List of Local labels at the end of first statement in the macro definition.

 

Study Material, Lecturing Notes, Assignment, Reference, Wiki description explanation, brief detail
Microprocessor and Microcontroller : 8086 Microprocessor : Macros - 8086 Microprocessor |


Privacy Policy, Terms and Conditions, DMCA Policy and Compliant

Copyright © 2018-2024 BrainKart.com; All Rights Reserved. Developed by Therithal info, Chennai.