BIT151 Microprocessor and Computer Architecture

Microprocessor and Computer ArchitectureUnit 39 min read

8085 Instruction Set & Addressing Modes: Formats, Types, and Real-World Traces

Unit 3 of Microprocessor and Computer Architecture covers the 8085 microprocessor’s instruction set (classification, formats, and timing), addressing modes (how operands are specified), and practical programming examples—essential for designing low-level code and interfacing hardware in embedded systems.

TAKEAWAYS:

  • The 8085 instruction set is divided into 5 types (data transfer, arithmetic, logic, branch, and stack/machine control) with 7 addressing modes to specify operands.
  • Instruction format determines opcode length (1–3 bytes) and operand fields, directly impacting execution time (e.g., MVI A, 08H takes 10 T-states vs. ADD B’s 4).
  • Addressing modes like direct, register indirect, and immediate enable flexible operand access; HL pair is critical for memory operations.
  • Worked examples (e.g., finding the smallest array element) show how to combine instructions and loops, while timing diagrams reveal clock-cycle overheads.
  • Real-world applications include Khalti’s payment validation (branch instructions for error handling) and NTC’s traffic light control (timed loops via RST and JMP).
  • Exam focus: Trace execution cycles, differentiate modes, and calculate T-states for given instructions.

1. Instruction Set of 8085: Classification and Formats

The 8085 instruction set is fixed-length (opcodes 1–3 bytes) and categorized into 5 types, each serving distinct functions. The format of an instruction defines how the opcode and operands are encoded, affecting memory usage and execution speed.

1.1 Classification of Instructions

The 8085 instructions are grouped as follows:

MOV (Register ↔ Register/Accumulator)MVI (Immediate to register/memory)LDA/LHLD (Load from memory)STA/SHLD (Store to memory)Data TransferADD/SUB (Binary addition/subtraction)INC/DEC (Increment/Decrement)DAD (16-bit addition: HL + BC/DE/SP)ArithmeticANA/ORA/XRA (AND/OR/XOR with accumulator)CMP (Compare, sets flags)LogicJMP/JC/JNC (Unconditional/Conditional jumps)CALL/RET (Subroutine calls/returns)BranchPUSH/POP (Stack operations)EI/DI (Enable/Disable interrupts)HLT (Halt processor)Stack & Machine Control8085 Instruction Set
Hierarchical classification of 8085 instructions with icons for clarity

Key Point:

  • Single-byte opcodes (e.g., MOV B, C) execute faster (4 T-states) than multi-byte ones (e.g., MVI M, 34H takes 10 T-states).
  • Accumulator (A) is involved in most arithmetic/logic operations.

1.2 Instruction Formats

The 8085 uses 3 primary formats:

02467Opcode8 bitsOperand8 bitsAddress16 bits
Generic 8085 instruction format (1-3 bytes)
Format Example Bytes T-states Description
1-byte (Opcode only) NOP, HLT 1 4 No operands; simplest instructions.
2-byte (Opcode + 8-bit) MVI B, 05H 2 7 Immediate data or register transfer.
3-byte (Opcode + 16-bit) LXI H, 2000H 3 10 Load 16-bit address into HL/BC/DE/SP.

Visual: Instruction Format Fields


Example: The instruction ADD B has:

  • Opcode: 10000010 (8 bits, 82H in hex).
  • No operand field (register B is implied).

Worked Example: Timing Calculation Question: How long does MVI A, 08H take at 5 MHz? Solution:

  • Clock period = .
  • T-states for MVI A, 00H = 7 (from datasheet).
  • Execution time = .

2. Addressing Modes: How Operands Are Specified

Addressing modes determine how the operand is located in memory or registers. The 8085 supports 7 modes:

Data is part of instruction (e.g., `MVI B, 50H`)ImmediateOperand in register (e.g., `MOV C, B`)RegisterMemory at HL/BC/DE (e.g., `MOV A, M`)Register Indirect16-bit address follows opcode (e.g., `STA 2100H`)DirectOperand implied (e.g., `INR B`)ImplicitOperand on stack (e.g., `POP H`)Stack8085 Addressing Modes
Addressing modes with examples and visual cues for quick recall

Comparison Table:

Mode Example Bytes Use Case
Immediate MVI C, 0AH 2 Load constant values.
Register ADD B 1 Fast register-to-register ops.
Register Indirect MOV A, M 1 Access memory via HL pair.
Direct LDA 3000H 3 Load from specific memory location.
Implicit DAA 1 Adjust accumulator after arithmetic.

Key Point:

  • HL pair is critical for register indirect mode (e.g., MOV A, M reads from [HL]).
  • Direct addressing uses 3 bytes (opcode + 16-bit address), slowing execution.

3. Worked Example: Finding the Smallest Element in an Array

Problem: Write an 8085 program to find the smallest element in an array stored at 2000H (10 bytes). Assume B holds the array size.

2501218221354
Array state after comparing elements (smallest = 5 at index 4)

Solution:

        LXI H, 2000H   ; Load array start address to HL
        MOV A, M       ; Load first element to A (initial min)
        INR H          ; Move to next element
        MOV C, B       ; Load array size to C (counter)
LOOP:   MOV B, M       ; Load current element to B
        CMP B          ; Compare with A (min)
        JNC NEXT       ; Jump if A ≤ B (no update)
        MOV A, B       ; Else, update min
NEXT:   INR H          ; Move to next element
        DCR C          ; Decrement counter
        JNZ LOOP       ; Repeat until all elements checked
        ; A now holds the smallest element

Trace Execution:

  1. Initialization: HL = 2000H, A = [2000H] (first element).
  2. Loop:
    • Compare A with [HL].
    • If [HL] < A, update A.
    • Increment HL and decrement counter (C).
  3. Termination: After 10 iterations, A contains the smallest value.

Real-World Tie-In: This logic is used in NEPSE’s stock price analysis (finding the lowest price in a day’s trading data) or Khalti’s fraud detection (identifying the smallest transaction amount in a batch).


4. Instruction Cycle and Timing Diagrams

Every instruction executes in fetch-decode-execute cycles. The timing diagram for LDA 2100H (3-byte instruction) is:

T1Fetch Opcode(M[15:0] → IR)T2Fetch Operand Byte1 (M[15:0] → Temp)T3Fetch Operand Byte2 (M[15:0] → Temp)T4Fetch Operand Byte3 (M[15:0] → Temp)T5Decode & Execute(Load [2100H] → A)T6-T13Memory AccessCycles (if needed)
Timing diagram for `LDA 2100H` (13 T-states total, 3-byte instruction)

Key Observations:

  • Multi-byte instructions require extra fetch cycles.
  • Memory access (e.g., LDA) adds latency compared to register ops (ADD B).

5. In the Real World

  1. Khalti’s Payment Validation:

    • Uses conditional jumps (JC/JNC) to check if a transaction amount exceeds limits.
    • Example: CMP A, 50000 followed by JNC REJECT (reject if amount ≥ 50,000).
  2. NTC’s Traffic Light Control:

    • Timed loops with DCR and JNZ to cycle lights every 30 seconds.
    • Example:
      MVI C, 30       ; 30-second count
      LOOP: CALL DELAY ; Delay subroutine
            DCR C
            JNZ LOOP
      
  3. Daraz’s Order Queue Management:

    • Stack operations (PUSH/POP) prioritize urgent orders.
    • Example: PUSH H saves the current order pointer before processing.

6. Exam Tip

  • Memorize T-states: Know the execution time for common instructions (e.g., MOV = 4, MVI = 7, LDA = 13).
  • Trace step-by-step: For programs, show register/memory changes at each step.
  • Differentiate modes: In exams, always specify which addressing mode is used (e.g., "direct addressing in STA 3000H").
  • Calculate timing: Given a clock frequency, compute execution time (e.g., 5 MHz → 0.2 µs per T-state).

Based on the TU BIT syllabus for Microprocessor and Computer Architecture (BIT151), unit 3.

Discussion

Loading…