edited by
3,715 views
8 votes
8 votes

Which of the following macros can put a macro assembler into an infinite loop?

  1. .MACRO M1, X
    .IF EQ, X   ;if X=0 then
    M1 X + 1
    .ENDC
    .IF NE, X   ;if X ≠ O then
    .WORD X  ;address (X) is stored here
    .ENDC
    .ENDM
    
  2. .MACRO M2, X
    .IF EQ, X
    M2 X
    .ENDC
    .IF NE, X
    .WORD X + 1
    .ENDC
    .ENDM
  1. (ii) only
  2. (i) only
  3. both (i) and (ii)
  4. None of the above
edited by

2 Answers

Best answer
11 votes
11 votes

If $M2$ macro is called with $X=0$, then the macro assembler will go into an infinite loop.

For $M1$  the argument  is incremented for the recursive call and so the macro expansion will happen maximum $2$ times.

Hence, correct option: A.

edited by
0 votes
0 votes

The macro that can put a macro assembler into an infinite loop is (ii) only.

Here's why:

Let's analyze macro M2:

.MACRO M2, X
    .IF EQ, X
        M2 X   ; Recursive call with the same argument X
    .ENDC
    .IF NE, X
        .WORD X + 1   ; This line will be expanded for each recursive call
    .ENDC
.ENDM

In macro M2, if the condition .IF EQ, X is true, it makes a recursive call to itself with the same argument X. This creates an infinite loop because the recursive call will keep expanding with the same argument, leading to an endless cycle.

On the other hand, macro M1 does not have a recursive call within the macro itself. It uses recursion in a way that avoids infinite looping.

Answer:

Related questions

38 votes
38 votes
2 answers
4
Kathleen asked Oct 9, 2014
12,698 views
The pass numbers for each of the following activitiesobject code generationliterals added to literal tablelisting printedaddress resolution of local symbols that occur in...