GATE / CS ARCHIVE

GATE CSE 1996 / QUESTION 6(a)

Trace an output-port counter

Computer Organization & Architecture · Instructions & Addressing Modes · Full GATE CSE 1996 paper

GATE 1996, Q6(a) Descriptive
Report issue

Instructions & Addressing Modes

Question 6(a), GATE 1996: For an 8085-style system with output port 00H, analyze the program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT. What does it do to the port? GFG includes OUT and INR but calls the CPU 8052; GateForum calls it 8085 but omits OUT and INR.
Question 6(a), GATE 1996: For an 8085-style system with output port 00H, analyze the program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT. What does it do to the port? GFG includes OUT and INR but calls the CPU 8052; GateForum calls it 8085 but omits OUT and INR.
Tap to enlarge
Answer & solution

Answer: Outputs 00H, 01H, …, FFH repeatedly (no official key was published)

Interpret the instructions as 8085 instructions: PCHL copies HL into the program counter. The byte addresses are 0100–0101 for MVI A,00H and 0102–0104 for LXI H,0105H. Therefore the next instruction, OUT 00H, starts at 0105H. OUT occupies two bytes, INR A one, PCHL one, so the loop is OUT at 0105H, INR at 0107H, PCHL at 0108H. HLT at 0109H is never reached.

Initialization sets A=0 and HL=0105H once. Each iteration writes A to the port, increments A modulo 256, then jumps back to OUT. Consequently the port receives 0,1,2,…,255,0,…, an indefinitely repeating eight-bit count. An external DAC would turn this into a staircase ramp, but a DAC is not part of the stated hardware.

The two reproductions cannot be treated as one literal program. Thus the port remains at its previous value, which is unspecified.

Original paper, page 7