GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Trace a repeating output-port counter

2 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Use instruction lengths to resolve HL=0105H as the OUT instruction, then follow OUT, INR and PCHL to derive the byte sequence and its three low-bit waveforms. Both source subparts use the same loop; waveform generation adds bit projection.

Descriptive
Report issue

Trace an output-port counter

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

Descriptive
Report issue

Draw the counter output bits

Input/Output, DMA & Interrupts

Question 6(b), GATE 1996: For the output-port program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT., show the three least significant output-bit waveforms. Account for the differing GateForum program without OUT and INR.
Question 6(b), GATE 1996: For the output-port program ORG 0100H; MVI A,00H; LXI H,0105H; OUT 00H; INR A; PCHL; HLT., show the three least significant output-bit waveforms. Account for the differing GateForum program without OUT and INR.
Tap to enlarge
Answer & solution

Answer: D0=01010101…, D1=00110011…, D2=00001111… (no official key was published)

Sample immediately after successive OUT instructions. The low-three-bit output words are 000,001,010,011,100,101,110,111,000,… . Reading each column gives D0: 0 1 0 1 0 1 0 1; D1: 0 0 1 1 0 0 1 1; D2: 0 0 0 0 1 1 1 1. These eight samples repeat. Between output writes the port latch holds its previous value, so each column is a rectangular waveform, not a series of impulses.

If Δ is the interval between writes, D0 has period 2Δ, D1 period 4Δ and D2 period 8Δ, all with 50% steady-state duty cycle. In normal 8085 timing OUT takes 10 T-states, INR A takes 4 and PCHL takes 6, so Δ=20 T-states without interrupts or wait states. Their periods are therefore 40,80,160 T-states. If only qualitative waveforms are required, the relative periods suffice.

Initialization precedes the first write, so the output before that write is not specified. This result belongs to the instruction stream interpreted as 8085.

Original paper, page 7