IAE Academy

GATE 2018 IN Q.45: solution and answer

GATE 2018 · INQ.45 · 2 marks · NAT

A portion of an assembly language program written for an 8-bit microprocessor is given below along with explanations. The code is intended to introduce a software time delay. The processor is driven by a 5 MHz clock. The time delay (in s) introduced by the program is ________.

        MVI B, 64H   ; Move immediate the given byte into register B. Takes 7 clock periods.
LOOP :  DCR B        ; Decrement register B. Affects Flags. Takes 4 clock periods.
        JNZ LOOP     ; Jump to address with Label LOOP if zero flag is not set. Takes
                     ; 10 clock periods when jump is performed and 7 clock periods when
                     ; jump is not performed.
See the question in the paper

Answer and solution

ANSWER

The program introduces a delay of .

Official answer: 279 to 282Source: Official answer key, GATE 2018 IN (IIT Guwahati)

  1. Convert the loop count to decimal: . So starts at 100, and the loop body DCR B runs 100 times, once for each value from 100 down to 1.

  2. JNZ LOOP jumps whenever after the decrement. That happens 99 times, after becomes . On the 100th pass becomes 0, the zero flag is set (), and the jump is not taken. This happens once.

  3. Count the clock periods (T-states) for each instruction:

  4. Total: clock periods.

  5. Clock period: . The question says each count is in clock periods of the 5 MHz clock that drives the processor.

  6. Delay: .

KEY IDEA

For a delay loop with an initial count , the loop body runs times, but the conditional jump is taken only times and falls through once, at its shorter not-taken time. The total T-states are , and the delay is . Convert a hexadecimal count such as to decimal first.

WATCH OUT FOR

Reading as decimal 64 gives T-states, or . Another error is to halve the 5 MHz clock, as if it were an 8085 crystal frequency, which doubles the answer to . The question states that the processor itself is driven by a 5 MHz clock, so . Counting the jump as taken all 100 times is also wrong, even though it happens to land inside the key's range here.

From the GATE 2018 IN paper. Every question of this paper · Download the full paper · All 9 Processors & memory questions, with notes

More Processors & memory questions