0 ratings 0% found this document useful (0 votes) 12 views 9 pages Macro Processor Introduction Basic
The document discusses the concept of macro instructions in assembly language programming, which allow programmers to define single instructions that represent blocks of code for repeated use, enhancing coding efficiency and program structure. It explains the functionality of macro processors, including the use of arguments and conditional macro expansion, which provide flexibility and control in code generation. Additionally, it highlights the ability to call macros within other macros, further simplifying complex programming tasks.
AI-enhanced title and description
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here .
Available Formats
Download as PDF or read online on Scribd
Carousel Previous Carousel Next
Save macro processor introduction basic For Later macro language
and the macro processor
The assembly language programmer often finds it Necessary to repeat some
blocks of code many times in the course of a program. The block may consist of
code to save or exchange sets of registers, for example, of code to set up linkages
or perform a series of arithmetic operations. In this situation the programmer
Gia instructions (often called
will find a macro instruction facility-useful.
ine a ions for grou
macro, the programmer essentially defines a single “instruction” to represent a
block of code. For every occurrence of this one-line macro instruction in his pro-
gram, the macro processing assembler will substitute the entire block.»
By defining the appropriate macro instructions, an assembly language pro-
grammer can tailor his own higher level facility in a convenient manner, at no
cost in control over the structure of his program. He can achieve the conciseness
and ease in coding of high level languages without losing the basic advantage of
assembly language programming. Integral macro operations simplify debugging
and program modification and they facilitate standardization. Many computer
manufacturers use macro instructions to automate the writing of “tailored”
operating systems in a process called systems generation.
Macro instructions are usually considered an extension of the basic assembler
language, and the macro processor is viewed as an extension of the basic assem-
bler algorithm. As a form_of programming language, however, macro instruction
languages-differ significantly from assembly Janguages and compiled algebraic
languages, Important-analogs are to be found in some high level languages and
text editing systems.
In this section we will discuss an assembler macro facility. We will treat the use
of macro instructions in programming and the implementation of macros within
an assembler. Certain features that are characteristic of most macro processors
will be introduced and developed.
wtMACRO Nap,
U
12 x
1
iS
4.1. MACRO insTRUCTION!
a macro is an
In its simplest form, abbreviation for a seq
.
s simplest forn
ior the Following PORT n' Of 6,
Consi ce
Example 1:
1,DATA Add contents of DATA to register 4
A ‘Add contents of DATA to register 2
2, DATA aT eres ,
4 i ‘Add contents of DATA to register 3 ,
A 3, DATA 4
‘Add contents of DATA to register 1
‘ Hy a ‘Add contents of DATA to register 2
a 3,DATA Add contents of DATA to register 3
A ,
DATA O0C FS’
Inthe above program the sequence
1,DATA
2,DATA
3, DATA
\ ee
Occurs twice. A macro facility permits us to attach a name to this sequence and
to use this name in its place. We can invent a macro language that allows usto
specify the above as a macro definition and allows us to refer to ‘the definition
later. We have chosen to use a 360-type macro language.
_ A.macto processor effectively constitutes a separate language processor with
itsown language,
/ Me attach a name to a sequence by means of a macro instruction definition,
‘Which is formed in the following mariner: ———
Start of definition
‘Sequence to be abbreviated
a
MEND
fi
( 1
End of definition
iacne LANGUAGE AND THE MACRO PROCESSOR
113
3
MACRO pseudo-op i: i
Cie se ae op is the first line of the definition and identifies the fol-
owi nacro instruction name. Following the name line is the
of_instructi (i fi
seu eon The being abbreviated—the instructions comprising the
mai The definition is terminated by a line with the MEND
(‘macro end’) pseudo-op.
ong the macro has peso deh the_use of the macro name as.an. operation
-an_assembly program is equivalent to the use of the corresponding
mnemonic
fnstruction sequ Our example might be rewritten as follows, assigning the
~~» ‘{NCR’ to the repeated sequence.
name
Source | Expanded source
MACRO
INCR
A 1,DATA |
& A 2:DATA
2 A 3,DATA |
MEND
INCR | A. 1,DATA
' A 2,DATA
l A 3,DATA
INCR A 4,DATA
: A 2IDATA
; | ne 3,DATA
DATA pe F's" | DATA pe” rs
In this case the macro processor replaces each macro call with the lines
A 4, DATA
A 2, DATA [ke
A 3.DATA
the macro. Notice that the
comentis called expanding. iat
t ne defini-
macro definition itself does not apPcay in the expan'
tion is saved by the macro processor. The occurrence in th
| the. macro name, as an_operation. mnemonic to be expande!
a) :
ded source code. T'
¢ source program of
d, is called a macro
This proce:414 FEATURES OF AMACRo »,
bg ‘
4.2: FEATURES OF A MACRO FACILITY
4.2.1 Macro Instruction Arguments
The macro facility presented thus far is capable of inserting blocks of
tions in place of macro calls. Alll of the calls to any given macro wil] be rey
by identical blocks. This macro facility lacks flexibility: there is no y,.
specific macro call to modify the coding that replaces it. An important Xt,
Of this facility consists of providing for arguments, or parameters, in mac,
Corresponding macro dummy arguments will appear in macro defini
sider the following program.
Example 2:
\
A 1,DATA1
A 2,DATA1
A 3,DATA1
A 1,DATA2
A 2,DATA2
A 3,DATA2
DATA1 DC Fo
DATA2 DC F'10"
In this case the instruction sequences are very similar but no identical!
first sequence performs an operation using DATAI as operand: the second,
DATA2. They can be considered to perform the same operation with avait
Parameter, Or argument. Such a parameter is called a macro insiruction’.
ment, or “dummy argument;” it is specified on the macro name line aid!
tinguished (as a macro language symbol rather than an assembly languag
bol) by the ampersand (&), which is always its first character. The pret!
program could be written as:po LANGUAGE AND THE MACRO PRocesson
mac!
Source si
Expand.
MACRO Macro INCR has | ded source
INCR BARG | One argument ,
A 1,8ARG
A 2,BARG/ \_~
A 3,8ARG /
MEND |
INCR DATA Use DATAY | ;
a
Poesia {2 ian
on oni | A 3DATAI
INCR DATA2 Use DATA?
operand | { a Lpataa
: | A 3,DATA2
< FS’
DATAL DG a DATA1 pc FS?
DATAz OC 10 jeara: BE ft
:
It is possible to supply more than one argument in a macro call. Each axpu-
ment must cortespond to a definition (“dummy”) argument on the iiaero name
line of the macro_definitionWhen a macro call is processed, the arguments sup-
plied are substituted for the respective dummy arguments in the macro
definition. =
Consider the following program:
Example 3:
Loop! A 1,DATA1
A 2, DATA2
A 3, DATAS
Loor2 A 1, DATA3
A 2, DATA2
A 3,DATA1
DATA1 DC FS!
DATA2 DC F'10"
DATA3 DC FIs"ao PERT UR EE OP RACKS Fa,
V6
gre different, on are
cence ee mn
In thi ands in the compe : could be written as
on a aa Bats of the sequences. THIS program
EXPANDED a0,
SOURCE
RO \
twen BARG1 BARGZBARCS
era 1A 1 ARG1
eA 2.&ARGZ
A 3RKARG3
MEND |
, sazpares | LooPt A
Loop? «NCR DATA1,DA A
\ A
‘ /DATAA \ LOOP2 A
Loor2 INCR DATAS,DATA2 A
\ a
: Bi | DATA DC
FS)
ee | cares
DATA3 DC F158" BATA eC
: |
flere we have specified four arguments, including
arguments are treated just like those written as “operan
tion; the argument appearing in the label field on the macro name
calls to the macro differs from other arguments only in its location.
used.as labels within the macro need not appear in the label field o
arguments appearing in tl
fhe label field of a call may be used asope
the macro instruction code. Lab
el arguments are convenient buts
features that enhance the similarity between macro instructi
ions ai
assembly language instructions. Following is another encoding ofpo LANGUAGE AND THE MACRO PRocesson
mac!
"7
5 vac , Expanded source
3 INCR BARG1&ARG2,
rt aoe SARGBLAR
girs) 2,8&ARG2
— 3,8ARG3 |
MEND
INCR DATAI,DATA2,DATA3,
, }LOOP1! {Loopy
A 4.DATAL
A 2oaTa2
: 3,DATAS
incr DATAS.DATA2,DATA1,LOOP2, (Loop?
1DATAZ
| A 2.DATA2
A 3,DATAT
There are generally two_ways-of specifying arguments to a macro call The
fust, positional argiment, is demonstrated inthe preceding examples: Arsw.
ments are matched with dummy arguments according to the order in which they
appear. Thus, in a macro call INCR A,B,C’ A, B, and C replace the first, second,
and third dummy arguments. A more general argument facility, keyword ae
ments, allows reference to dummy arguments by name as well as by position.
Referring to the dummy arguments appearing in the definition of INCR, we
might write
&ARG2=B! or ‘INCR &ARG 1=A,&ARG2=BARG3=C’.
‘INCR &ARG1=A, &ARG3="
This can be useful when a macro has arguments fabels, for example—that are
not always needed. Any arguments not supplied are presumed_blank by the
macro processor.
4.2.2, Conditional Macro Expansion
Two important macro processor pseudo:
reordering of the sequence of macro-expansion.
of the machine instructions that appear in expansi
Consider the following program:
yp, AIF and AGO, permit conditional
This allows conditional selection
ions of a macro call.Example 4:
Loop: a
a 1,DATAL
a 2, DATAZ
3, DATAS
Loor2 a 1, DATAZ
a 2, DATA2
Loops A 1,DATAI
DATA1 DC 5
DATA2 0c F’10"
DATA3 DC F’15"
ands, labels, and the number of instructions gener
In this example, the oper:
Id be written as follows:
change in each sequence. This program cou.
MACRO
&ARGO VARY Be &ARG1,&ARG2,8ARG3
&ARGO A 1,8A)
AIF (écounr EQ 1).FINI Test if & COUNT =
A 2,8ARG'
AIF FE SUNT EQ 2).FINI Test if & COUNT =
A 3,8ARG3 oa oS
FINI MEND Expanded source
Loop! VARY BDATALDATA2,DATAS | { LOOPt =A LDAT:
A
| A 30aT)
Loop2 - VARY_~—s2,DATA3,DATA2 Loop2 ADT
: | A 20a0
Loops VARY 1,DATA1 | | Loops = ASCANAT
DATA1 DG F's!
DATA2 OC F'10"
DATA3 OC F15'Quack AND THE MACRO PROCESS
Oo .
pret Pi with a period (.), such as FIN}, 574 me Meg
js HT giput of the Macro processor. The Res ety
Pees a) Ute ance 4 eee eet colt are
fie) date ynesponding (© RCOUNT isa tome
ua ame ¢ with the statement following the Alp Phew + the macro process,
jae With | an do-op,
e ‘conti conditional branch pseudo-op, it performs an . th
PAF iS ir the tested condition is true, The agg she fst ant
ies oop or “go 10" statement, 10 specifies a label sn ational
wement in the macro instruction definition; the a a ae
ner ential processing of instructions with the indicated state
jos a sre directives. 10 the macro processor and do not ‘apes
Pee Just 3s conditional and unconditional branch icatro ms
git 3 mstructions in a
SONS — age program direct the order of program flow, AIF and Aco n
* equenc in which the macro processor expands the statements in ma
cag. This makes it possible to tailor specific occurrences of in
iets. Fe i =
er to their various contexts. If machine language branches and tests are
en y will waste execution time; also, the tests and unused instructions wil
in the macro instruction language per-
at assemble selectively, and by testing
TATE (CG
et labetted Fy
we
CESS con.
fement
é of ae
5 i. call, omit code not needed. This facility for selective assem-
hi shly general macros is one of the systems programmer's most powerful
saming tools.
423 Macro Calls Within Macros
: cro calls are “abbreviations” of instruction sequences, it seems reason-
z that such “abbreviations” should be available within other macro defini-
tions. For example,
Sample 5:
MACRO
ADDI &ARG
L 1, &ARG
A 1, =F
ST 1, &ARG
MEND
MACRO
ADDS &ARG1, BARG2, &ARGS
A0D1 &ARGI
me &ARG2
uenp BARG3
i sparate calls 10 ° Oe
tin the definition of the macro ‘ADDS’ are three 2