can someone explaine this to me? Given a macro definition as the following, what
ID: 3661902 • Letter: C
Question
can someone explaine this to me?
Given a macro definition as the following, what is the expansion result of a macro 7. invocation like "RDBUFF oE,BUFFER,LENGTH..80"? (5%) RDBUFF MACRO &INDEV;, &BUFADR; &RECLTH; &EOR;,&MAXLTH; (&EOR; NE IF &EORCK; ENDIF CLEAR LOOP COUNTER CLEAR X CLEAR A (&EORCK; EQ 1) IF LDCH XT&EOR;' SET EOR CHARACTER RMO A, S ENDIF (&MAXLTH; EQ LDT #4096 SET MAX LENGTH 4096 ELSE SET MAXIMUM RECORD LENGTH +LDT H&MAXLTH; ENDIF SLOOP TD X &INDEV; TEST IN PUT DEVICE JEQ SLOOP LOOP UNTIL READY RD X &INDEV;" READ CHARACTER INTO REG A (&EORCK; EQ 1) COMPR AS TEST FOR END OF RECORD JEQ EXIT LOOP IF EOR ENDIF STCH &BUFADR; X STORE CHARACTER IN BUFFER TIXR. T LOOP UNLESS MAXIMUM LENGTH JLT SLOOP HAS BEEN REACHED SEXIT STX &RECLTH; SAVE RECORD LENGTH MENDExplanation / Answer
Macro Processors:
Macro is a unit of specification for program generation through expansion. A macro represents a commonly used group of statements in the source programming language.The macro processor replaces each macro instruction with the corresponding group of source language statements. This is called expanding of macros.
A macro consists of a name , a set of formal parameters and body of code.
Macro definitions consists of
(1). Macro prototype (2). One or more model (3). Macro processor
Macro definition is in between a macro header statement and macro end statement.
Syntax of macro prototype statement:-
<macro name> [ < formal parameter spec > [ ;...]]
where
< macro name > = it is in the mnemonic field of an assembly statement
< formal parameter spec > is in the following form
< parameter name > [ < parameter kind > ]
Syntax of the macro call is
< macro name > [ < actual parameter spec > [;..]]
Macro Expansion:-
(a). Expansion time control flow
(b). Lexical substitution
Algorithm for Macro Expansion:-
1. Initialise the macro expansion counter (MEC).
2. Check the statement which is pointed MEC is not a mend statement.
(a) if statement is model statement
then expand the statement and
increment the MAC by 1
else
MAC:= new value specified in the statement
3. Exit from the macro expansion.
Solution:-
RDBUFF F31 , BUF, RECL , 04, 2048
CLEAR X CLEAR LOOP COUNTER
CLEAR A
LDCH =X'04' SET EOR CHARACTER
RMO A,S
+LDT #2048 SET MAXIMUM RECORD LENGTH
$AALOOP TD =X'F3' TEST INPUT DEVICE
JEQ $AALOOP LOOP UNTIL READY
RD =X'F3' READ CHARACTER INTI REG A
COMPR A,S TEST FOR END OF RECORD
JEQ $AAEXIT EXIT LOOP IF EOR
STCH BUF, X STORE CHARACTER IN BUFFER
TIXR T LOOP UNLESS MAXIMUM LENGTH
JLT $AALOOP HAS BEEN REACHED
$AAEXIT STX RECL SAVE RECORD LENGTH
* Hope you know the basic macro syntax
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.