MicroprocessorUnit 213 min read
8085 Architecture, Instructions & Programming: Registers, Flags, ALU, Bus Cycles
Unit 2 of Microprocessor covers the 8085 microprocessor’s internal architecture (registers, ALU, control unit), its 74-instruction set (data transfer, arithmetic, logic, stack, I/O), and programming basics including addressing modes and assembly language syntax. Learn how instructions execute in machine cycles, how fla
Core Architecture of 8085
The 8085 is an 8-bit microprocessor introduced by Intel in 1976. It is widely used in embedded systems and educational contexts due to its simplicity and efficiency. Below is a breakdown of its key components:
Registers
The 8085 has several registers that play crucial roles in executing instructions:
classDiagram
class Registers {
+ A (Accumulator): 8-bit
+ B, C, D, E, H, L: 8-bit
+ SP (Stack Pointer): 16-bit
+ PC (Program Counter): 16-bit
+ PSW (Flags): 8-bit
}
class Flags {
+ S (Sign): Negative result
+ Z (Zero): Zero result
+ AC (Auxiliary Carry): Carry from bit 3
+ P (Parity): Even parity
+ CY (Carry): Carry from bit 7
}
Registers --> Flags : "Contains"
class ALU {
+ Operations: ADD, SUB, AND, OR, XOR, etc.
}
Registers --> ALU : "Uses"Arithmetic Logic Unit (ALU)
The ALU performs arithmetic and logical operations on data. It takes inputs from registers and produces results that are stored back in registers or memory. The ALU also sets flags based on the outcome of operations.
Control Unit
The control unit manages the execution of instructions by generating control signals. It decodes instructions and coordinates data flow between the ALU, registers, memory, and I/O devices.
Instruction Set of 8085
The 8085 instruction set is categorized into five groups:
- Data Transfer Instructions
- Arithmetic Instructions
- Logic Instructions
- Branch Instructions
- Stack, I/O, and Machine Control Instructions
Data Transfer Instructions
These instructions move data between registers, memory, and I/O devices. Examples include:
MOV: Move data between registers or memory.MVI: Move immediate data to a register or memory.LXI: Load immediate data into a 16-bit register pair.
Example:
MVI A, 32H ; Move immediate value 32H to Accumulator (A)
STA 2050H ; Store Accumulator value at memory location 2050H
Arithmetic Instructions
These instructions perform arithmetic operations like addition, subtraction, increment, and decrement.
Example:
MVI B, 10H ; Move 10H to register B
MVI C, 05H ; Move 05H to register C
ADD B ; Add B to A
Logic Instructions
These instructions perform logical operations like AND, OR, XOR, and complement.
Example:
MVI A, 0FH ; Move 0FH to Accumulator
CMA ; Complement Accumulator (A = 0F0H)
Branch Instructions
These instructions alter the flow of execution based on conditions.
Example:
JNZ LOOP ; Jump to LOOP if Zero flag is not set
Stack, I/O, and Machine Control Instructions
These instructions manage the stack, input/output operations, and control the microprocessor.
Example:
PUSH B ; Push register B onto the stack
POP C ; Pop data from the stack into register C
Instruction Execution: Machine Cycles and Bus Cycles
sequenceDiagram
participant CPU as 8085 CPU
participant MEM as Memory
participant IO as I/O Device
CPU->>MEM: T1: Fetch Opcode (MVI A, 32H)
MEM-->>CPU: T2: Return Opcode
CPU->>MEM: T3: Fetch Operand (32H)
MEM-->>CPU: T4: Return Operand
CPU->>CPU: T5: Execute (Load A = 32H)
CPU->>IO: T6: Write to Port (if I/O involved)
Note over CPU: Machine Cycle = 1-5 T-states
Note over MEM: Bus Cycle = T1-T4Bus Cycles in a Single Instruction (MVI A, 32H)Machine Cycles
A machine cycle is the time taken by the 8085 to complete one operation, such as fetching an instruction or reading/writing data. There are four types of machine cycles:
- Fetch Cycle: Fetch an instruction from memory.
- Memory Read Cycle: Read data from memory.
- Memory Write Cycle: Write data to memory.
- I/O Read/Write Cycle: Read/write data to/from I/O devices.
Bus Cycles
A bus cycle is the time taken to complete a single operation on the address, data, and control buses. Each machine cycle consists of one or more bus cycles.
Example: Timing Diagram for MVI A, 32H
Addressing Modes
The 8085 supports several addressing modes to access data:
| Addressing Mode | Description | Example |
|---|---|---|
| Immediate | Operand is part of the instruction | MVI A, 32H |
| Register | Operand is in a register | MOV B, A |
| Direct | Operand is in memory | STA 2050H |
| Register Indirect | Operand is in memory via register | LDAX B (Load A from BC) |
| Stack | Operand is on the stack | PUSH B |
Programming Example: Adding Two Numbers
Problem: Add two numbers stored in memory locations 2050H and 2051H, and store the result in 2052H.
LDA 2050H ; Load first number into A
ADD 2051H ; Add second number to A
STA 2052H ; Store result in memory
Trace:
LDA 2050H: Loads data from2050HintoA.ADD 2051H: Adds data from2051HtoA.STA 2052H: Stores the result in2052H.
In the Real World
eSewa (Nepal): The 8085-like architecture is used in embedded systems for processing transactions. For example, when you pay a bill via eSewa, the microprocessor handles data transfer between the app, server, and bank. The
MOVandADDinstructions are analogous to moving transaction data and calculating totals.ATM Machines (Global): ATMs use microprocessors similar to the 8085 for basic operations. When you insert a card and enter a PIN, the microprocessor reads the card data (like
LDAinstructions) and verifies it against the bank’s database (usingCMPinstructions).Traffic Light Control Systems (Nepal): Traffic light systems use microprocessors to manage timings. The
JNZ(Jump if Not Zero) instruction can be used to loop through different timings for red, yellow, and green lights based on sensor inputs.
Exam Tip
Draw Timing Diagrams: Always draw timing diagrams for instructions like
MVI,LDA, orSTAto show how bus cycles work. Examiners love detailed timing diagrams with labeled states (T1, T2, etc.).Compare Instructions: Be ready to compare similar instructions like
PUSHvs.POP,MOVvs.MVI, orADDvs.ADC. Highlight differences in operands, flags affected, and usage.Programming Examples: Write short programs (3-5 instructions) to solve simple problems. Use comments to explain each step. For example:
; Add two numbers and store result MVI A, 10H ; Load first number ADD B ; Add second number (from B) STA 2000H ; Store resultFlags and Their Use: Know which flags are set by each instruction. For example,
ADDsetsCY(Carry),Z(Zero), andS(Sign). Practice predicting flag states after operations.Addressing Modes: Memorize the addressing modes and when to use each. For example, use immediate for constants and direct for memory locations.
Comparison: 8085 vs. 8086
| Feature | 8085 | 8086 |
|---|---|---|
| Data Bus Width | 8-bit | 16-bit |
| Address Bus Width | 16-bit (64KB address space) | 20-bit (1MB address space) |
| Instruction Set | 74 instructions | Extended (includes 8085 instructions) |
| Memory Access | Single bus for address/data | Multiplexed address/data bus |
| Stack Pointer | 16-bit | 16-bit |
| Program Counter | 16-bit | 16-bit |
| Interrupts | 5 (TRAP, RST 7.5, RST 6.5, RST 5.5, INTR) | 256 (via interrupt vector table) |
| Clock Speed | 3 MHz | 5 MHz |
Key Difference: The 8086 uses a multiplexed address/data bus, which means the address and data share the same bus but are transmitted at different times. This is necessary because the 8086 has a 16-bit data bus but a 20-bit address bus, requiring more pins than the 8085.
Worked Example: Calculating Loan Interest (Bank Scenario)
Problem: A bank uses a microprocessor to calculate simple interest for a loan. The formula is: Where:
- = Principal (stored in memory at
2000H) - = Rate (stored at
2001H) - = Time (stored at
2002H)
Solution in 8085 Assembly:
LDA 2000H ; Load Principal (P) into A
MOV B, A ; Copy P to B
LDA 2001H ; Load Rate (R) into A
MUL B ; Multiply P and R (A = P * R)
MOV C, A ; Store result in C
LDA 2002H ; Load Time (T) into A
MUL C ; Multiply (P * R) by T
MOV D, A ; Store result in D
MVI A, 100 ; Load 100 into A
DIV D ; Divide (P * R * T) by 100
STA 2003H ; Store Interest in memory
Explanation:
- Load the principal (
P) from2000HintoA. - Multiply
Pby the rate (R) from2001H. - Multiply the result by the time (
T) from2002H. - Divide by 100 to get the interest.
- Store the result in
2003H.
Real-World Tie-In:
Banks use microprocessors in ATMs and backend systems to perform such calculations quickly. The 8085’s arithmetic instructions (MUL, DIV, ADD) are foundational for financial computations.
Summary Table: Key Instructions
| Instruction | Operation | Flags Affected | Example |
|---|---|---|---|
MOV |
Move data between registers/memory | None | MOV B, A |
MVI |
Move immediate data | None | MVI C, 05H |
ADD |
Add two numbers | CY, Z, S, P, AC | ADD B |
SUB |
Subtract two numbers | CY, Z, S, P, AC | SUB C |
JMP |
Jump to a specified address | None | JMP LOOP |
CALL |
Call a subroutine | None | CALL SUBROUTINE |
RET |
Return from subroutine | None | RET |
PUSH |
Push data onto the stack | None | PUSH B |
POP |
Pop data from the stack | None | POP C |
IN |
Input from a port | None | IN 01H |
OUT |
Output to a port | None | OUT 02H |
Final Notes
Practice Drawing Diagrams: Draw the block diagram of the 8085, timing diagrams for instructions, and logic diagrams for control signals. These are high-scoring questions in exams.
Understand Flags: Always check which flags are affected by an instruction. For example,
ADDaffectsCY,Z,S,P, andAC.Write Programs: Write small programs (5-10 instructions) to solve problems like adding numbers, comparing values, or managing a stack.
Compare with 8086: Be ready to explain differences in architecture, instruction sets, and addressing modes between 8085 and 8086.
By mastering these concepts, you’ll be well-prepared for both theoretical and practical questions in your exams!
Based on the TU BSc CSIT syllabus for Microprocessor (CSC167), unit 2.
Discussion
Loading…