System Programming Macro Notes
System Programming Macro Notes
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
MACRO
INCR_M &MEM_VAL=, &INCR_VAL=, ®=
MOVER ®, &MEM_VAL
ADD ®, &INCR_VAL
MOVEM ®, &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=, ®= AREG
MOVER ®, &MEM_VAL
ADD ®, &INCR_VAL
MOVEM ®, &MEM_VAL
MEND
+ 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, ®=BREG
MOVER BREG TMP
MEND
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.
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
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
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
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