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

1996

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

Macro (i), M1(X):

if X = 0: call M1(X + 1)
if X != 0: emit .WORD X

Macro (ii), M2(X):

if X = 0: call M2(X)
if X != 0: emit .WORD X + 1

Answer: A. (ii) onlyA macro assembler expands a recursive macro call by literal text substitution at assembly time, not by runtime execution. Expansion of a recursive macro…

  1. A.

    (ii) only

  2. B.

    (i) only

  3. C.

    Both (i) and (ii)

  4. D.

    None of the above

Attempted by 147 students.

Show answer & explanation

Correct answer: A

A macro assembler expands a recursive macro call by literal text substitution at assembly time, not by runtime execution. Expansion of a recursive macro terminates only if the argument passed to each successive recursive call eventually changes enough to satisfy the macro's own exit (non-recursive) branch. If a call regenerates the exact same argument that invoked it, the same branch keeps firing and the macro processor keeps emitting nested calls to itself without bound — this is the macro-assembler analogue of an infinite loop.

Tracing macro (i), M1(X), from X = 0:

  1. M1(0): X = 0, so the condition holds and M1 recursively calls M1(X + 1) = M1(1).

  2. M1(1): X = 1 ≠ 0, so this call takes the non-recursive branch and emits .WORD 1 — expansion of this branch stops here.

Tracing macro (ii), M2(X), from X = 0:

  1. M2(0): X = 0, so the condition holds and M2 recursively calls M2(X) = M2(0) — the same argument that triggered this call.

  2. M2(0) again: X is still 0, so the identical branch fires again, generating another M2(0), and so on indefinitely.

Compare the two recursions: M1's recursive argument is X + 1, so each expansion strictly increases X, guaranteeing the non-zero terminating branch is reached within one further step for any starting value — M1 always terminates. M2's recursive argument is X itself, so a call that starts at X = 0 can never leave the zero branch — it never terminates.

Therefore, among the two, only macro (ii) puts the macro assembler into an infinite loop.

Explore the full course: Iocl Engineers Officers Grade A Paper 2

Loading lesson…