RTUEE / EC / EEEYr 2020 · Sem 62020

Q4Microprocessors

Question

16 marks

Q.2. (a) Explain the following instructions of 8085 Microprocessor using suitable examples: (i) LXI (ii) XCHG (iii) SPHL (iv) LDA [12]

(b) Draw the timing diagram for the execution of instruction LXI Rp, 16 bit data. [4]

Answer

LXI, XCHG, SPHL, and LDA are further key 8085 data-transfer instructions for loading a register pair with an immediate 16-bit value, exchanging HL and DE contents, transferring HL into the stack pointer, and loading the accumulator directly from a specified memory address; the timing diagram for LXI Rp, 16-bit data shows three machine cycles (one opcode fetch and two memory read cycles) spanning a total of 10 T-states.

(a) Explanation of LXI, XCHG, SPHL, LDA Instructions

LXI (Load Register Pair Immediate): LXI Rp, 16-bit data loads the specified register pair (Rp: BC, DE, HL, or SP) directly with the 16-bit immediate value given in the instruction, with the low-order byte of the immediate data loaded into the lower register of the pair and the high-order byte into the higher register. For example, LXI H, 2050H loads L with 50H and H with 20H, so HL=2050H — LXI is commonly used at the start of a program to initialize a register pair with a memory pointer or a 16-bit constant value.

XCHG (Exchange HL and DE): this instruction simply swaps the contents of the HL register pair with the contents of the DE register pair — H exchanges with D, and L exchanges with E. For example, if HL=2050H and DE=3070H before execution, after XCHG, HL=3070H and DE=2050H — XCHG is frequently used in 8085 programs that need to use both HL-based and DE-based indirect addressing at different points, allowing a value computed in one register pair to be conveniently transferred to the other.

SPHL (Move HL to Stack Pointer): this instruction copies the 16-bit content of the HL register pair directly into the stack pointer (SP) register, replacing SP's previous value entirely. For example, if HL=2500H, executing SPHL sets SP=2500H — this instruction is useful when a program needs to dynamically relocate the stack to a different memory area (such as when switching between multiple independent stack regions for different tasks), since it allows the new stack pointer value to be computed using ordinary HL-register arithmetic and then transferred to SP in a single instruction.

LDA (Load Accumulator Direct): LDA 2050H loads the accumulator directly with the content of the memory location specified by the 16-bit address given in the instruction (2050H in this example) — unlike LHLD, which loads a full 16-bit register pair from two memory locations, LDA loads only the single 8-bit accumulator from a single specified memory location, using direct addressing.

None of these four instructions — LXI, XCHG, SPHL, LDA — affects any of the processor's status flags (S, Z, AC, P, CY), since each is purely a data-movement instruction rather than an arithmetic or logical operation; this is a general property of the 8085's data-transfer instruction group as a whole (MOV, MVI, LXI, LDA, STA, LHLD, SHLD, XCHG, SPHL, LDAX, STAX all leave the flag register completely unchanged), which is often exploited in practice by placing such instructions between a flag-setting arithmetic operation and a later conditional jump, without risk of disturbing the condition being tested.

(b) Timing Diagram for LXI Rp, 16-bit Data

Definition of a T-state: a T-state (clock period) is the most basic unit of time in the 8085's operation, corresponding to one full cycle of the processor's input clock signal (generated by the on-chip clock generator from an external crystal connected to the X1/X2 pins, and made available externally on the CLK OUT pin). Every internal processor operation and every external bus transaction is measured and specified in whole numbers of T-states; a machine cycle, in turn, is composed of a specific number of T-states (commonly 3, 4, 5, or 6, depending on the type of machine cycle), and a complete instruction is composed of one or more machine cycles. Because the T-state duration is fixed by the clock frequency (for example, a 3 MHz 8085 clock gives a T-state duration of 1/3,000,000 seconds, approximately 333 nanoseconds), knowing an instruction's total T-state count allows its exact execution time to be computed for any given clock frequency, which is essential in timing-sensitive applications such as generating precise delay loops or meeting the timing requirements of slower external peripheral devices.

The LXI Rp, 16-bit data instruction is a 3-byte instruction (one opcode byte followed by two data bytes: the low-order and then the high-order byte of the 16-bit immediate value), and its execution comprises three machine cycles: an opcode fetch (M1) followed by two memory read cycles (M2 and M3), one for each of the two immediate data bytes.

Timing Diagram: LXI Rp, 16-bit dataCLKALEAD0-7Addr(low)OpcodeAddr(low)Data(low)Addr(low)Data(high)A8-15Addr(high) held stable across M1-M3RD-barM1 (Opcode Fetch, 4T)M2 (Mem Read, 3T)M3 (Mem Read, 3T)

M1 (Opcode fetch, 4 T-states): during T1, the program counter's content is placed on the address bus (lower byte on AD0-AD7, upper byte on A8-A15), with ALE pulsed high to indicate valid address; during T2, RD-bar goes active-low and the opcode byte for LXI is fetched from memory into the instruction register via AD0-AD7 (now functioning as the data bus); T3 and T4 are used internally by the processor to decode the fetched opcode and recognize that two further immediate data bytes must be fetched next.

M2 (Memory read, 3 T-states): the program counter (now incremented) again places the next address on the bus with ALE pulsed, RD-bar goes active during T2 to fetch the low-order immediate data byte, which is loaded into the lower register of the specified register pair (e.g., L, if Rp=H).

M3 (Memory read, 3 T-states): identical in structure to M2, but fetching the high-order immediate data byte from the next incremented program-counter address, loading it into the higher register of the specified pair (e.g., H).

The complete LXI Rp, 16-bit data instruction therefore requires a total of 4+3+3=10 T-states to execute, and this three-machine-cycle, ten-T-state timing pattern is characteristic of all 3-byte 8085 instructions that load an immediate 16-bit value, providing a clear illustration of how an instruction's byte length directly determines the number of machine cycles (and hence execution time) it requires.

Contrast with a register-only instruction's timing: it is instructive to compare this 10 T-state, three-machine-cycle LXI timing against the timing of a simple register-only instruction such as MOV A,B or ADD C, each of which is only one byte long and therefore requires only a single machine cycle — the opcode fetch (M1) — with no further memory read or write cycles at all. This single M1 cycle itself takes exactly 4 T-states: T1 (address of the opcode placed on the bus, ALE pulsed), T2 (RD-bar active, opcode byte fetched into the instruction register), and T3-T4 (internal opcode decoding and, for register-to-register instructions, internal execution of the operation itself, entirely within the processor with no external bus activity). Thus a register-only instruction such as MOV A,B executes in just 4 T-states total, compared to the 10 T-states required for LXI Rp, 16-bit data — a direct consequence of LXI needing two additional memory-read machine cycles to fetch its two immediate data bytes, whereas MOV A,B needs no further bus activity whatsoever beyond the initial opcode fetch since both its source and destination operands are already held internally within the processor's register set.

Back to Paper