CACS155 Microprocessor and Computer Architecture

Microprocessor and Computer ArchitectureUnit 312 min read

8085 Instruction Set & Addressing Modes: Types, Examples & Real-World Use

Unit 3 of Microprocessor and Computer Architecture covers the 8085 microprocessor’s instruction set classification (data transfer, arithmetic, logic, branch, stack, I/O, machine control) and its six addressing modes (immediate, register, direct, register indirect, implied, and extended). This note explains each instruc


1. Instruction Set of 8085: Classification and Examples

The 8085 instruction set consists of 244 instructions categorized into 8 groups based on functionality. Each instruction performs a specific operation on data or controls program flow.

1.1 Classification of Instructions

The 8085 instructions are divided into the following categories:

Category Function Example Instructions
Data Transfer Move data between registers, memory, and I/O ports. MOV, MVI, LDA, STA, LXI, XCHG
Arithmetic Perform addition, subtraction, increment, decrement, and arithmetic shifts. ADD, SUB, INR, DCR, DAD
Logic Perform bitwise AND, OR, XOR, complement, and rotate operations. ANA, ORA, XRA, CMA, RLC
Branch (Jump/Conditional) Alter program flow based on conditions or unconditionally. JMP, CALL, RET, JNZ, JC
Stack, Pop, Push Manage stack operations (LIFO). PUSH, POP, XTHL, SPHL
I/O Instructions Transfer data between CPU and I/O devices. IN, OUT
Machine Control Halt, disable interrupts, enable interrupts, and reset operations. HLT, NOP, DI, EI, RIM, SIM
Rotate & Shift Rotate or shift bits within registers or memory. RLC, RRC, RAL, RAR, RAL, RAR

1.2 Worked Example: Data Transfer Instructions

Instruction: MOV B, A

  • Mnemonic: Move data from register A to register B.
  • Opcode: 47H
  • Operation:
    • The content of A is copied to B.
    • The source register (A) remains unchanged.
    • Flags affected: None.
02467Opcode8 bitsSource8 bitsDestination8 bits
Generic 8085 Data Transfer Instruction Format (e.g., MOV, LDA)

Example Trace: If (A) = 37H and (B) = 57H, after MOV B, A:

  • (A) = 37H (unchanged)
  • (B) = 37H (copied from A)

1.3 Worked Example: Arithmetic Instruction (ADD B)

Instruction: ADD B

  • Mnemonic: Add content of B to A.
  • Opcode: 80H
  • Operation:
    • (A) = (A) + (B)
    • Flags affected: S (Sign), Z (Zero), C (Carry), P (Parity), AC (Auxiliary Carry).

Example Trace: If (A) = 37H and (B) = 57H:

  • Binary addition:
    A: 0011 0111 (55)
    B: 0101 0111 (87)
    Sum: 1000 1110 (142)
    
  • Result: (A) = 8EH (142 in decimal)
  • Flags:
    • S = 1 (MSB is 1, negative in 8-bit signed)
    • Z = 0 (Result ≠ 0)
    • C = 1 (Carry generated)
    • P = 0 (Even parity)
    • AC = 1 (Auxiliary carry from bit 3 to 4)

2. Addressing Modes of 8085

Addressing modes determine how the operand is specified in an instruction. The 8085 supports six addressing modes:

Addressing Mode Description Example Instruction Operand Format
Immediate Operand is part of the instruction (literal value). MVI A, 32H 32H (8-bit)
Register Operand is a register (A, B, C, D, E, H, L). MOV B, A A (source), B (dest)
Direct Operand is a memory location (16-bit address). STA 2100H 2100H (memory address)
Register Indirect Operand is in memory, address stored in H-L pair. MOV A, M M (memory pointed by HL)
Implied Operand is implied (no operand specified). INR A None
Extended Used for JMP and CALL (16-bit address). JMP 3000H 3000H (16-bit address)

2.1 Worked Example: Immediate Addressing (MVI A, 32H)

Instruction: MVI A, 32H

  • Mnemonic: Move immediate value 32H to A.
  • Opcode: 3EH (for MVI A, data)
  • Operation:
    • The 8-bit literal 32H is loaded into A.
    • Flags affected: None.

Example Trace:

  • Before: (A) = ? (unknown)
  • After: (A) = 32H (50 in decimal)

2.2 Worked Example: Direct Addressing (STA 2100H)

Instruction: STA 2100H

  • Mnemonic: Store A into memory location 2100H.
  • Opcode: 32H (for STA addr)
  • Operation:
    • The 16-bit address 2100H is specified.
    • The content of A is written to 2100H.
    • Flags affected: None.

Example Trace:

  • If (A) = 45H and (2100H) = ? (unknown):
    • After STA 2100H: (2100H) = 45H

2.3 Worked Example: Register Indirect (MOV A, M)

Instruction: MOV A, M

  • Mnemonic: Move data from memory (pointed by H-L) to A.
  • Opcode: 7EH
  • Operation:
    • The 16-bit address in H-L is used to fetch data.
    • Data at (HL) is copied to A.
    • Flags affected: None.

Example Trace:

  • If (H) = 20H, (L) = 00H → (HL) = 2000H
  • If (2000H) = 67H and (A) = ?:
    • After MOV A, M: (A) = 67H, (2000H) remains unchanged.

3. Real-World Applications of 8085 Instructions & Addressing Modes

3.1 eSewa (Nepal) – Transaction Processing

  • Instruction Used: ADD, SUB, STA (Direct Addressing)
  • How?
    • When a user pays an electricity bill via eSewa, the 8085-like processor (or modern equivalent) in the backend system:
      1. Fetches the user’s balance (LDA 3000H – Direct Addressing).
      2. Subtracts the bill amount (SUB 20H – Immediate Addressing).
      3. Stores the updated balance (STA 3000H – Direct Addressing).
    • Addressing Mode: Direct (for memory access) and Immediate (for fixed bill amount).

3.2 Daraz (Nepal) – Order Queue Management

  • Instruction Used: MOV, INR, JNZ (Register & Implied Addressing)
  • How?
    • Daraz’s order processing system (simplified for 8085 logic):
      1. Initializes an order counter (MVI B, 00H – Immediate).
      2. Loops through orders (INR B – Implied, increments counter).
      3. Checks if orders are processed (CMP 10H – Immediate, compares with max orders).
      4. Jumps back if not done (JNZ LOOP – Conditional Jump).
    • Addressing Mode: Implied (for INR B) and Immediate (for fixed values).

3.3 Ncell (Nepal) – SMS Delivery System

  • Instruction Used: LXI, MOV, OUT (Register Indirect & I/O)
  • How?
    • When an SMS is sent via Ncell:
      1. Loads the SMS data into H-L (LXI H, 4000H – Register Indirect).
      2. Moves data to a buffer (MOV A, M – Register Indirect).
      3. Sends via I/O port (OUT 03H – I/O Addressing).
    • Addressing Mode: Register Indirect (for memory access) and I/O (for modem communication).

4. Comparison of Addressing Modes

Feature Immediate Register Direct Register Indirect Implied Extended
Operand Location Inside instruction Register Memory (16-bit) Memory (via H-L) None Memory (16-bit)
Speed Fastest Fast Medium Medium Fastest Slowest
Flexibility Low (fixed value) High Medium High Low Medium
Example Instruction MVI A, 32H MOV B, A STA 2100H MOV A, M INR A JMP 3000H
Use Case Loading constants Fast register ops Memory access Stack/array operations Auto-increment Jumps/Calls

5. Instruction Execution: Worked Example (Full Trace)

Problem: Write the 8085 assembly program to add two numbers stored at 2000H and 2001H, store the result at 2002H, and check if the result is zero.

RegistersA=35HMemory2000H=35HALU35H+4AH=7FHControl UnitFetch/Decode/Execute
8085 Instruction Pipeline During ADD Operation

Solution:

LDA 2000H    ; Load first number (Direct Addressing)
ADD 2001H    ; Add second number (Direct Addressing)
STA 2002H    ; Store result (Direct Addressing)
JNZ NOT_ZERO ; Jump if result ≠ 0 (Conditional Jump)
HLT          ; Halt if result = 0
NOT_ZERO: HLT

Step-by-Step Trace:

  1. LDA 2000H

    • (A) = (2000H) (e.g., 35H)
    • Flags: Updated (S, Z, P, etc.)
  2. ADD 2001H

    • (A) = (A) + (2001H) (e.g., 35H + 4AH = 7FH)
    • Flags: Updated (C=0, Z=0, S=0, P=1)
  3. STA 2002H

    • (2002H) = (A) = 7FH
  4. JNZ NOT_ZERO

    • Since Z=0, jump to NOT_ZERO.
    • If (A) = 00H, Z=1, so no jump (halt).

6. Exam Tip: How to Score Full Marks

  1. Define Clearly:

    • Always start with definitions (e.g., "Addressing mode is a technique to specify the operand in an instruction.").
    • Example:

      "Immediate addressing is an addressing mode where the operand is part of the instruction itself."

  2. Use Examples:

    • For every instruction, provide:
      • Opcode (if asked).
      • Operation (what it does).
      • Flags affected (if any).
    • Example for ADD B:

      "The ADD B instruction adds the content of register B to A. The opcode is 80H. Flags affected: S, Z, C, P, AC."

  3. Trace Execution:

    • For programs, show step-by-step register/memory changes.
    • Example:

      "After MOV B, A, if (A)=37H, then (B)=37H."

  4. Compare Addressing Modes:

    • Use a table to compare speed, flexibility, and use cases.
    • Example:

      "Immediate addressing is fastest but least flexible, while register indirect is slower but more flexible for arrays."

  5. Link to Real-World:

    • In short-answer questions, relate instructions to eSewa, Daraz, or Ncell.
    • Example:

      "The STA instruction (Direct Addressing) is used in eSewa to update a user’s balance in memory."

  6. Avoid Common Mistakes:

    • ❌ Don’t assume flags are affected unless specified (e.g., MOV does not affect flags).
    • ❌ Don’t mix up 8-bit and 16-bit operations (e.g., DAD is 16-bit, ADD is 8-bit).
    • ❌ Don’t forget to initialize registers before use (e.g., MVI B, 00H).

Final Checklist for Exam:

✅ Define the instruction/addressing mode. ✅ Give an example with opcode (if asked). ✅ Trace execution (register/memory changes). ✅ Mention flags affected (if any). ✅ Compare with other modes (if comparison is asked). ✅ Relate to real-world (eSewa, Daraz, Ncell).


LDA 2000H: Fetchdata (35H) from MemoryADD 2001H: Fetchdata (4AH) from MemorySTA 2002H: Storeresult (7FH) to MemoryJNZ NOT_ZERO:Check Z flag (Z=0) → J
8085 Instruction Execution Flow (Direct Addressing Example)

Immediate (e.g., MVI A, 32H)Direct (e.g., STA 2100H)Register Indirect (e.g., MOV A, M)Register (e.g., ADD B)Stack (e.g., PUSH/POP)ADDRESSING_MODEZero (Z)Carry (CY)Sign (S)FLAGINSTRUCTION
8085 Instruction-Addressing-Flag Relationship

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

Discussion

Loading…