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, 08Htakes 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
RSTandJMP). - 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:
Key Point:
- Single-byte opcodes (e.g.,
MOV B, C) execute faster (4 T-states) than multi-byte ones (e.g.,MVI M, 34Htakes 10 T-states). - Accumulator (
A) is involved in most arithmetic/logic operations.
1.2 Instruction Formats
The 8085 uses 3 primary formats:
| 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,82Hin hex). - No operand field (register
Bis 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:
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, Mreads 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.
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:
- Initialization:
HL = 2000H,A = [2000H](first element). - Loop:
- Compare
Awith[HL]. - If
[HL] < A, updateA. - Increment
HLand decrement counter (C).
- Compare
- Termination: After 10 iterations,
Acontains 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:
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
Khalti’s Payment Validation:
- Uses conditional jumps (
JC/JNC) to check if a transaction amount exceeds limits. - Example:
CMP A, 50000followed byJNC REJECT(reject if amount ≥ 50,000).
- Uses conditional jumps (
NTC’s Traffic Light Control:
- Timed loops with
DCRandJNZto cycle lights every 30 seconds. - Example:
MVI C, 30 ; 30-second count LOOP: CALL DELAY ; Delay subroutine DCR C JNZ LOOP
- Timed loops with
Daraz’s Order Queue Management:
- Stack operations (
PUSH/POP) prioritize urgent orders. - Example:
PUSH Hsaves the current order pointer before processing.
- Stack operations (
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…