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? (i) M1(X): if X = 0, call M1(X + 1); if X != 0, emit .WORD X. (ii) M2(X): if X = 0, call M2(X); if X != 0, emit .WORD X + 1.

  1. A.

    (ii) only

  2. B.

    (i) only

  3. C.

    Both (i) and (ii)

  4. D.

    None of the above

Attempted by 26 students.

Show answer & explanation

Correct answer: A

A macro assembler can enter an infinite expansion loop if recursive macro expansion repeats with no change in the argument. In M2, when X = 0, the condition is true and the macro expands to M2(X), again with X = 0. Thus a call such as M2(0) keeps expanding forever. In M1, when X = 0, the recursive call is M1(X + 1), so the argument changes to a nonzero value and the expansion can stop. Therefore, only macro (ii) can put the macro assembler into an infinite loop.

Explore the full course: Gate Guidance By Sanchit Sir