0% found this document useful (0 votes)
5 views

System Programming Macro Notes

Uploaded by

S.V ki batei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views

System Programming Macro Notes

Uploaded by

S.V ki batei
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

Introduction of Macro

Definition: Macro is a unit of specification for program generation through expansion.


Define MACRO INCR for Move-Add-Move using Lexical Expansion call INCR A, B, AREG
Example:
MACRO
INCR &MEM_VAL, &INCR_VAL, &REG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG, &MEM_VAL
MEND

Macro consists: macro Header and Macro End


Marco header starts with MACRO
Macro Prototype: Name and Set of formal Parameters (Positional Parameter (default),
Keyword Parameter)

Body of MACRO Consists:


One or More Model Statement
Macro Preprocessor Statement
Macro Ends with MEND
How to call Macro:
Macro is called from assembly program:
Macro Name with set of actual parameters. [Expansion takes place]
INCR A, B, AREG
Macro call leads to Macro Expansion:
Macro Call replaced by Assembly Statement
Expanded Statement are marked with + in the label Field
( Label Field, opcode field, operand field)

+ MOVER &REG, &MEM_VAL


+ ADD &REG, &INCR_VAL
+ MOVEM &REG, &MEM_VAL

Flow of Execution:
Default Sequential (No preprocessor Statement)
If Macro Consists of Preprocessor Statement:
Alter the flow of control
Conditional Expansion and Expansion time loops

Flow of Control implemented by MEC: (Macro Expansion Counter)


Algorithm:

1. MEC := Statement no of first Statement following prototype statement


2. While MEC is not MEND statement
a) If a model statement
i) Expand the statement
ii) MEC := MEC + 1
b) Else ( ie Preprocessor Statement)
i) MEC := New Value Specified in statement
3) Exit from Macro Expansion
Positional Parameters:
&<parameter Name>
Example: &sample
Keyword Parameter:
<parameter Name> is ordinary String
<parameter Kind> is = string
Example:

MACRO
INCR_M &MEM_VAL=, &INCR_VAL=, &REG=
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG, &MEM_VAL
MEND

Call:
INCR_M MEM_VAL=A, INCR_VAL=B, REG=AREG
INCR_M INCR_VAL=B, REG=AREG, MEM_VAL=A
Note: Order of parameter is immaterial
Default Specification of Parameter:
A default is a standard assumption in absence of explicit specification
Explicit Specification Overrides the default Values
MACRO
INCR_D &MEM_VAL=, &INCR_VAL=, &REG= AREG
MOVER &REG, &MEM_VAL
ADD &REG, &INCR_VAL
MOVEM &REG, &MEM_VAL
MEND

INCR_D MEM_VAL=A INCR_VAL=B,


INCR_D INCR_VAL=B, MEM_VAL=A
INCR_D INCR_VAL=B, MEM_VAL=A, REG=BREG

Macro with mixed parameter list:


Macro can be defined with both Positional and Keyword Parameter
Rule: Here positional parameter precede Keyword parameter
Other Uses: used formal parameter in operand field (Not restricted)
Can be used in opcode Field and Label field in model statement.
MACRO
CALC &x, &y, &op=MULT, &LAB=
&LAB MOVER &AREG, &x
ADD &AREG, &y
MOVEM &AREG, &x
MEND

Call: CALC A, B, LAB=Loop


Expansion:
+ Loop MOVER &AREG, A

+ ADD &AREG, B
+ MOVEM &AREG, A

Nested Macro
Model Statement in macro can call another Macro
Such calls are known as Nested Macro
Macro expansion takes place according to LIFO method

Example:
MACRO
COMPUTE &FIRST, &SECOND
MOVEM BREG, TMP
INCR_D &FIRST, &SECOND, &REG=BREG
MOVER BREG TMP
MEND

NOTE: Here Macro COMPUTE contain another Macro INCR_D


+ MOVEM BREG TMP + MOVER &AREG, A
COMPUTE X, Y + INCR_D X, Y + ADD &AREG, B
+ MOVER BREG, TMP + MOVEM &AREG, A
Advanced Macro Facilities
Advanced Macro facilities aimed at supporting semantic expansion
They are:
1) Alteration of flow of control
2) Expansion time variable
3) Attributes of parameter

Alteration of flow of control:


1) Expansion time Sequencing Symbol (SS)
2) Expansion time statement (AIF, AGO, ANOP)

Sequencing Symbol:
Syntax : . <ordinary string>
SS is defined in Label Field.
SS is used as a operand in AIF and AGO statement to transfer control.

AIF (Alter IF)


Syntax: AIF (<expression>) <.Sequencing Symbol>
Here expression is a relational expression
If true then control is transfer to SS in label field.

AGO:
Syntax: AGO <Sequencing Symbol>
Transfer the control to SS unconditionally.

ANOP:
ANOP Statement is just used for defining SS.
Expansion Time Variables
Two Types
1) Local EV Created for particular MACRO
2) Global EV Created for all MACRO in program
EV are created/declared through Declaration Statement
LCL <EV Specification> [, <EV Specification>…] Example: LCL &A, &B
GBL <EV Specification> [, <EV Specification>…] Example: GBL &A, &B

Syntax: &<EV name>


Where EV name is ordinary string,
Value of EV can be manipulated through preprocessor statement SET
Syntax: <EV Specification> SET <SET Expression>
Label Field Opcode Field Operand Field
Example: &A SET 1
EV Value can be used in model and AIF Statement

MACRO
CONSTANTS
LCL &A
&A SET 1
DB &A
&A SET &A + 1
DB &A
MEND
Attributes of Formal parameter:
Syntax: <attribute name>’ <formal parameter specification>
Type, Length and Size represented as T, L, S
Example:

MACRO
DCL_CONSTANT &A
AIF (L’ &A EQ 1) .NEXT
…..
…..
.NEXT …..
…..
…..
MEND

Conditional expansion:
Based on the condition Model Statements are visited.
AIF and AGO are used for this purpose

Example: Write a EVAL MACRO to evaluate A-B+C in AREG.


Note: If first two parameter are same, EVAL generate single MOVER to load third parameter.
MACRO
EVAL &X, &Y, &Z
AIF (&X EQ &Y) .ONLY
MOVER AREG, &X
SUB AREG, &Y
ADD AREG, &Z
AGO .OVER
.ONLY MOVER AREG, &Z
.OVER MEND
Expansion Time Loops:
It is necessary to generate many similar statements during expansion of Macro. This can be
achieved by writing similar model statement in Macro.
Example:
MACRO
CLEAR &A + MOVER AREG, =’0’ Output:

MOVER AREG, =’0’ + MOVEM AREG, B B=0

MOVEM AREG, &A + MOVEM AREG, B + 1 B+1=0

MOVEM AREG, &A + 1 + MOVEM AREG, B + 2 B+2=0

MOVEM AREG, &A + 2


MEND

CALL: CLEAR B
On expansion Macro store value in 3 consecutive bytes with address B, B+1, B+2
Alternatively similar can be achieved by expansion time loop.
EV loop can be written using
1) EV variables and AIF and AGO
Example:
MACRO + MOVER AREG, =’0’ Input:
X=B, N=3
CLEAR &X, &N
+ MOVEM AREG, B M=0
LCL &M AREG=0
+ MOVEM AREG, B + 1
&M SET 1 Output:
+ MOVEM AREG, B + 2 B=0
MOVER AREG, =’0’
B+1=0
MOVEM AREG, &X B+2=0

.MORE MOVEM AREG, &X + &M


&M SET &M + 1
AIF (&M NE N) .MORE
MEND
CALL: CLEAR B, 3
Other way of Expansion Time Loop:
Many Assembler provides facilities as above.
But M68000 and Intel 8088 processor provide explicit expansion time looping constructs.

Two Facilities are as under:


M68000 Syntax:
REPT <Expression>
--------
-------- Get processed upto expression no (times)
ENDM

Example:
MACRO
CONST10
LCL &M
&M SET 1 Initial value
REPT 10 10 time execution
DC ‘&M’ 1, 2, 3, …… 10
&M SET &M + 1 Counter increment
ENDM
MEND
Intel 8088 Syntax:
IRP <Formal Parameter>, <argument list>
Example:
MACRO 4, 10
CONSTS &M, &N, &Z Here Z gets successive value from argument list
IRP &Z, &M, 7, &N

DC ‘&Z’
ENDM
MEND

You might also like