8085 Instruction Set
Open in the Padhaiko app2.6 Instruction set of 8085
The Intel 8085 microprocessor features an instruction set of 74 distinct instructions that expand into 246 operational codes (opcodes) out of a total possible 256 combinations (10 opcodes are undefined/unimplemented).
Based on their functional application and internal datapath behavior, the 8085 instructions are classified into five functional groups:
- Data Transfer (Copy) Group
- Arithmetic Group
- Logical Group
- Branching Group
- Machine Control and Stack Group
1. Data Transfer (Copy) Group
These instructions copy 8-bit or 16-bit binary data from a source location to a destination location (between registers, between register and memory, or directly between memory and Accumulator) without altering the source contents.
| Mnemonic | Operands | Description & Micro-Operation | Bytes | Cycles (T-states) | Flags Affected |
|---|---|---|---|---|---|
MOV | Rd, Rs | Move register to register: Rd <- Rs | 1 | 1 (4T) | None |
MOV | M, Rs | Move register to memory: [HL] <- Rs | 1 | 2 (7T) | None |
MOV | Rd, M | Move memory to register: Rd <- [HL] | 1 | 2 (7T) | None |
MVI | R, data8 | Move immediate byte into register: R <- data8 | 2 | 2 (7T) | None |
MVI | M, data8 | Move immediate byte into memory: [HL] <- data8 | 2 | 3 (10T) | None |
LXI | Rp, data16 | Load 16-bit immediate data into register pair (B, D, H, SP) | 3 | 3 (10T) | None |
LDA | addr16 | Load Accumulator direct from memory: A <- [addr16] | 3 | 4 (13T) | None |
STA | addr16 | Store Accumulator direct to memory: [addr16] <- A | 3 | 4 (13T) | None |
LHLD | addr16 | Load H and L registers direct: L <- [addr16], H <- [addr16 + 1] | 3 | 5 (16T) | None |
SHLD | addr16 | Store H and L registers direct: [addr16] <- L, [addr16 + 1] <- H | 3 | 5 (16T) | None |
LDAX | Rp | Load Accumulator indirect through register pair BC or DE: A <- [Rp] | 1 | 2 (7T) | None |
STAX | Rp | Store Accumulator indirect through register pair BC or DE: [Rp] <- A | 1 | 2 (7T) | None |
XCHG | None | Exchange 16-bit contents of DE pair with HL pair: H <-> D, L <-> E | 1 | 1 (4T) | None |
2. Arithmetic Group
Performs 8-bit addition, subtraction, increment, decrement, 16-bit addition, and decimal adjustment. Unless specified otherwise, all arithmetic operations use the Accumulator as one operand and store the result in the Accumulator.
| Mnemonic | Operands | Operation Performed | Bytes | Cycles (T-states) | Flags Affected |
|---|---|---|---|---|---|
ADD | R / M | Add register or memory [HL] to Accumulator: A <- A + (R/M) | 1 | 1 (4T) / 2 (7T) | All (S, Z, AC, P, CY) |
ADI | data8 | Add immediate byte to Accumulator: A <- A + data8 | 2 | 2 (7T) | All (S, Z, AC, P, CY) |
ADC | R / M | Add with Carry: A <- A + (R/M) + CY | 1 | 1 (4T) / 2 (7T) | All (S, Z, AC, P, CY) |
ACI | data8 | Add immediate byte with Carry: A <- A + data8 + CY | 2 | 2 (7T) | All (S, Z, AC, P, CY) |
SUB | R / M | Subtract register or memory from A: A <- A - (R/M) | 1 | 1 (4T) / 2 (7T) | All (S, Z, AC, P, CY) |
SUI | data8 | Subtract immediate byte from A: A <- A - data8 | 2 | 2 (7T) | All (S, Z, AC, P, CY) |
SBB | R / M | Subtract with Borrow: A <- A - (R/M) - CY | 1 | 1 (4T) / 2 (7T) | All (S, Z, AC, P, CY) |
SBI | data8 | Subtract immediate with Borrow: A <- A - data8 - CY | 2 | 2 (7T) | All (S, Z, AC, P, CY) |
INR | R / M | Increment register or memory by 1: R <- R + 1 or [HL] <- [HL] + 1 | 1 | 1 (4T) / 3 (10T) | S, Z, AC, P (CY NOT affected) |
DCR | R / M | Decrement register or memory by 1: R <- R - 1 or [HL] <- [HL] - 1 | 1 | 1 (4T) / 3 (10T) | S, Z, AC, P (CY NOT affected) |
INX | Rp | 16-bit increment of register pair (BC, DE, HL, SP): Rp <- Rp + 1 | 1 | 1 (6T) | None |
DCX | Rp | 16-bit decrement of register pair (BC, DE, HL, SP): Rp <- Rp - 1 | 1 | 1 (6T) | None |
DAD | Rp | 16-bit addition to HL: HL <- HL + Rp | 1 | 3 (10T) | CY ONLY (S, Z, AC, P untouched) |
DAA | None | Decimal Adjust Accumulator (converts sum in A to packed BCD) | 1 | 1 (4T) | All (S, Z, AC, P, CY) |
3. Logical Group
Performs bitwise boolean operations, comparisons, rotations, and bit inversions on data in the Accumulator.
| Mnemonic | Operands | Operation Description | Bytes | Cycles (T-states) | Flags Affected |
|---|---|---|---|---|---|
ANA | R / M | Bitwise AND with Accumulator: A <- A AND (R/M) | 1 | 1 (4T) / 2 (7T) | CY=0, AC=1, S, Z, P |
ANI | data8 | Bitwise AND immediate: A <- A AND data8 | 2 | 2 (7T) | CY=0, AC=1, S, Z, P |
ORA | R / M | Bitwise OR with Accumulator: A <- A OR (R/M) | 1 | 1 (4T) / 2 (7T) | CY=0, AC=0, S, Z, P |
ORI | data8 | Bitwise OR immediate: A <- A OR data8 | 2 | 2 (7T) | CY=0, AC=0, S, Z, P |
XRA | R / M | Bitwise Exclusive-OR: A <- A XOR (R/M) | 1 | 1 (4T) / 2 (7T) | CY=0, AC=0, S, Z, P |
XRI | data8 | Bitwise Exclusive-OR immediate: A <- A XOR data8 | 2 | 2 (7T) | CY=0, AC=0, S, Z, P |
CMP | R / M | Compare with Accumulator (evaluates A - (R/M) without altering A) | 1 | 1 (4T) / 2 (7T) | All (S, Z, AC, P, CY) |
CPI | data8 | Compare immediate with Accumulator (evaluates A - data8) | 2 | 2 (7T) | All (S, Z, AC, P, CY) |
CMA | None | One's complement of Accumulator: A <- NOT A | 1 | 1 (4T) | None |
CMC | None | Complement Carry flag: CY <- NOT CY | 1 | 1 (4T) | CY only |
STC | None | Set Carry flag to 1: CY <- 1 | 1 | 1 (4T) | CY only |
RLC | None | Rotate Accumulator Left without Carry (bit 7 copies to CY and bit 0) | 1 | 1 (4T) | CY only |
RRC | None | Rotate Accumulator Right without Carry (bit 0 copies to CY and bit 7) | 1 | 1 (4T) | CY only |
RAL | None | Rotate Accumulator Left Through Carry (9-bit rotation) | 1 | 1 (4T) | CY only |
RAR | None | Rotate Accumulator Right Through Carry (9-bit rotation) | 1 | 1 (4T) | CY only |
| Comparison Result | Carry Flag (CY) | Zero Flag (Z) | Explanation |
|---|---|---|---|
| A < Operand | 1 | 0 | Subtraction requires a borrow into MSB -> CY = 1, Z = 0. |
| A == Operand | 0 | 1 | Subtraction yields exactly zero (A - Operand = 0) -> CY = 0, Z = 1. |
| A > Operand | 0 | 0 | Subtraction is positive and non-zero -> CY = 0, Z = 0. |
4. Branching Group
Alters the normal sequential execution of instructions by loading a new target address into the Program Counter (PC).
- Unconditional Branching:
JMP addr16: Unconditional jump.PC <- addr16(3 bytes, 3 cycles: OF, MR, MR = 10T).CALL addr16: Unconditional subroutine call. PushesPConto stack, thenPC <- addr16(3 bytes, 5 cycles: OF, MR, MR, MW, MW = 18T).RET: Unconditional return from subroutine. Pops return address from stack intoPC(1 byte, 3 cycles: OF, MR, MR = 10T).PCHL: Jump indirect. CopiesHLintoPC:PC <- HL(1 byte, 1 cycle: OF = 6T).
- Conditional Branching:
- Evaluates a specific status flag. If condition is TRUE, branch occurs; if FALSE, execution continues sequentially.
- Conditional Jumps (3 bytes): 10 T-states if taken (OF, MR, MR); 7 T-states if not taken (OF, MR).
JC(Jump if Carry:CY = 1) /JNC(Jump if No Carry:CY = 0)JZ(Jump if Zero:Z = 1) /JNZ(Jump if Not Zero:Z = 0)JM(Jump if Minus:S = 1) /JP(Jump if Positive:S = 0)JPE(Jump if Parity Even:P = 1) /JPO(Jump if Parity Odd:P = 0)
- Conditional Calls (3 bytes): 18 T-states if taken; 9 T-states if not taken.
CC,CNC,CZ,CNZ,CM,CP,CPE,CPO.
- Conditional Returns (1 byte): 12 T-states if taken (OF, MR, MR + internal); 6 T-states if not taken (OF + internal).
RC,RNC,RZ,RNZ,RM,RP,RPE,RPO.
- Restart Instructions (Software Interrupts):
RST n(n = 0 to 7): Pushes currentPConto stack and branches to fixed vector address(n * 8):RST 0->0000H,RST 1->0008H,RST 2->0010H,RST 3->0018HRST 4->0020H,RST 5->0028H,RST 6->0030H,RST 7->0038H
5. Machine Control and Stack Group
Controls CPU operational states and manipulates the LIFO stack pointer.
| Mnemonic | Operands | Operation Description | Bytes | Cycles (T-states) | Flags Affected |
|---|---|---|---|---|---|
PUSH | Rp / PSW | Push 16-bit pair or Program Status Word (A + Flags) onto stack | 1 | 3 (12T) | None |
POP | Rp / PSW | Pop top 16-bit word from stack into register pair or PSW | 1 | 3 (10T) | POP PSW modifies all flags; others none |
XTHL | None | Exchange top of stack with HL pair: L <-> [SP], H <-> [SP + 1] | 1 | 5 (16T) | None |
SPHL | None | Load Stack Pointer from HL pair: SP <- HL | 1 | 1 (6T) | None |
IN | port8 | Read byte from 8-bit I/O port into Accumulator: A <- Port[port8] | 2 | 3 (10T) | None |
OUT | port8 | Write byte from Accumulator to 8-bit I/O port: Port[port8] <- A | 2 | 3 (10T) | None |
EI | None | Enable Interrupts (sets internal interrupt enable flip-flop) | 1 | 1 (4T) | None |
DI | None | Disable Interrupts (resets internal interrupt enable flip-flop) | 1 | 1 (4T) | None |
HLT | None | Halt processor execution until hardware interrupt or reset | 1 | 1 (5T) | None |
NOP | None | No operation (consumes 4 T-states, used for software delay loops) | 1 | 1 (4T) | None |
SIM | None | Set Interrupt Mask and Serial Output Data (SOD) | 1 | 1 (4T) | None |
RIM | None | Read Interrupt Mask and Serial Input Data (SID) | 1 | 1 (4T) | None |
Worked Examples
1
An 8085 microprocessor executes the following assembly code segment:
LXI H, F000H
LXI B, 2000H
DAD BAssume prior to execution the status flags were: S=1, Z=1, AC=1, P=1, CY=0.
- Compute the 16-bit value in the HL register pair after executing
DAD B. - Determine the status of all five flags (
S, Z, AC, P, CY) followingDAD B. - Contrast this with the behavior of
INX Hon the Flag Register.
1. Computing the 16-Bit Sum in HL: The instruction DAD B adds the 16-bit content of register pair BC to register pair HL and stores the result in HL: HL <- HL + BC.
HL = F000H = 1111 0000 0000 0000B.BC = 2000H = 0010 0000 0000 0000B.
Perform 16-bit binary addition: F000H + 2000H = 11000H. The 16-bit register pair HL retains the lower 16 bits: HL = 1000H (Register H = 10H, Register L = 00H). A carry is generated out of the most significant bit (bit 15).
2. Evaluating Status Flags Following DAD B:
- Carry Flag (CY): A 16-bit overflow occurred from bit 15 -> CY = 1.
- Sign Flag (S): Untouched -> S = 1.
- Zero Flag (Z): Untouched -> Z = 1 (even though HL = 1000H is non-zero!).
- Auxiliary Carry (AC): Untouched -> AC = 1.
- Parity Flag (P): Untouched -> P = 1.
3. Contrast with INX H: If INX H were executed instead of DAD: INX H increments the 16-bit register pair HL by 1. INX and DCX instructions modify no flags whatsoever (not even the Carry flag). DAD modifies CY only, whereas INX/DCX modify no flags.
- Final contents:
HL = 1000H(H = 10H,L = 00H). - Flags: CY = 1; all other flags remain untouched (S = 1, Z = 1, AC = 1, P = 1).
DADupdates the Carry flag, whileINX/DCXmodify no flags at all.
2
For an Intel 8085 microprocessor, determine the binary states of the Carry Flag (CY) and Zero Flag (Z) after executing CPI 35H in three independent scenarios:
- When Accumulator contains
35H. - When Accumulator contains
50H. - When Accumulator contains
20H.
State in each case which conditional branch (JZ, JNZ, JC, JNC) will be taken.
CPI Operation Mechanism: CPI data8 subtracts the immediate byte data8 from the Accumulator internally (A - data8), updating the status flags while leaving the contents of the Accumulator unchanged.
Scenario 1: Accumulator A = 35H: Calculate A - 35H = 35H - 35H = 00H.
- Result is zero -> Zero Flag Z = 1.
- No borrow required -> Carry Flag CY = 0.
- Conditional jumps taken:
JZ(Jump on Zero) andJNC(Jump on No Carry).
Scenario 2: Accumulator A = 50H: Calculate A - 35H = 50H - 35H = 1BH (positive non-zero).
- Result is non-zero -> Zero Flag Z = 0.
- Since
A > 35H, no borrow is needed -> Carry Flag CY = 0. - Conditional jumps taken:
JNZ(Jump on Not Zero) andJNC(Jump on No Carry).
Scenario 3: Accumulator A = 20H: Calculate A - 35H = 20H - 35H = EBH (negative result, borrow required).
- Result is non-zero -> Zero Flag Z = 0.
- Since
A < 35H, a borrow into bit 7 is required -> Carry Flag CY = 1. - Conditional jumps taken:
JNZ(Jump on Not Zero) andJC(Jump on Carry).
- A = 35H: Z = 1, CY = 0 (
JZandJNCbranch). - A = 50H: Z = 0, CY = 0 (
JNZandJNCbranch). - A = 20H: Z = 0, CY = 1 (
JNZandJCbranch).
3
(Tribhuvan University Past exam questions Guide) An 8085 system initialises the Stack Pointer to 20F0H (SP = 20F0H). The CPU executes the following routine:
LXI H, 1234H
PUSH H
LXI B, 5678H
PUSH B
POP H
POP BTrace the contents of the Stack Pointer (SP), memory locations 20EEH, 20EFH, and register pairs BC and HL at every step.
1. Execution of LXI H, 1234H and PUSH H:
LXI H, 1234H:H = 12H,L = 34H.PUSH H: Decrements SP and stores high register H, then decrements SP and stores low register L:Memory[SP - 1] = Memory[20EFH] <- H = 12H.Memory[SP - 2] = Memory[20EEH] <- L = 34H.SP <- SP - 2 = 20EEH.
2. Execution of LXI B, 5678H and PUSH B:
LXI B, 5678H:B = 56H,C = 78H.PUSH B:Memory[SP - 1] = Memory[20EDH] <- B = 56H.Memory[SP - 2] = Memory[20ECH] <- C = 78H.SP <- SP - 2 = 20ECH.
3. Execution of POP H:
- Pops top of stack into low register L, then next byte into high register H, incrementing SP by 2:
L <- Memory[SP] = Memory[20ECH] = 78H.H <- Memory[SP + 1] = Memory[20EDH] = 56H.SP <- SP + 2 = 20EEH.
- Register pair HL now holds
5678H.
4. Execution of POP B:
- Pops next two bytes into BC:
C <- Memory[SP] = Memory[20EEH] = 34H.B <- Memory[SP + 1] = Memory[20EFH] = 12H.SP <- SP + 2 = 20F0H.
- Register pair BC now holds
1234H. - Notice that the two register pairs have swapped their contents through the stack!
After execution: SP = 20F0H; Memory[20EFH] = 12H, Memory[20EEH] = 34H; HL = 5678H (H = 56H, L = 78H); and BC = 1234H (B = 12H, C = 34H).
Exercises
Exercises
Classify the instruction set of Intel 8085 into five functional groups. Give two examples of instructions in each group, specifying their addressing modes and byte lengths.
Five Functional Instruction Groups of 8085:
- Data Transfer Group:
MOV B, M(Register Indirect Addressing Mode, 1 byte).MVI A, 45H(Immediate Addressing Mode, 2 bytes).
- Arithmetic Group:
ADD C(Register Addressing Mode, 1 byte).ADI 10H(Immediate Addressing Mode, 2 bytes).
- Logical Group:
ANA M(Register Indirect Addressing Mode, 1 byte).CPI 50H(Immediate Addressing Mode, 2 bytes).
- Branching Group:
JMP 3000H(Direct Addressing Mode, 3 bytes).JZ 2500H(Direct Addressing Mode, 3 bytes).
- Machine Control and Stack Group:
PUSH B(Register Indirect Addressing Mode, 1 byte).HLT(Implicit Addressing Mode, 1 byte).
The 8085 instruction set is grouped into Data Transfer (MOV B, M, MVI A, 45H), Arithmetic (ADD C, ADI 10H), Logical (ANA M, CPI 50H), Branching (JMP 3000H, JZ 2500H), and Machine Control/Stack (PUSH B, HLT).
Explain the operation of the DAA (Decimal Adjust Accumulator) instruction. Describe the specific conditions under which the processor adds 06H to the lower or upper nibble of the Accumulator.
DAA (Decimal Adjust Accumulator) Purpose and Rules: The DAA instruction converts the 8-bit binary result of an addition in the Accumulator into two valid packed BCD (Binary Coded Decimal) digits (each between 0 and 9):
- Lower Nibble Adjustment:
- If the value of the lower 4 bits (D0–D3) of the Accumulator exceeds
9(9H), OR if the Auxiliary Carry (AC) flag is set (AC = 1), the processor automatically adds06Hto the lower nibble of the Accumulator.
- If the value of the lower 4 bits (D0–D3) of the Accumulator exceeds
- Upper Nibble Adjustment:
- If the value of the upper 4 bits (D4–D7) of the Accumulator exceeds
9(9H), OR if the Carry (CY) flag is set (CY = 1), the processor automatically adds60Hto the upper nibble of the Accumulator and sets the Carry flag (CY = 1).
- If the value of the upper 4 bits (D4–D7) of the Accumulator exceeds
Concrete Example (BCD Addition: 38 + 49 = 87):
- Let
A = 38HandB = 49H. - Binary addition
ADD B:38H + 49H = 81H(1000 0001B). Lower nibble =8 + 9 = 17 = 11H, which generates an Auxiliary Carry (AC = 1). - Executing
DAA: SinceAC = 1, the processor adds06H:81H + 06H = 87H. - Final Accumulator content =
87H, which is the correct BCD sum!
DAA adjusts the binary sum in Accumulator to valid packed BCD by adding 06H to the lower nibble if D3–D0 > 9 or AC = 1, and adding 60H to the upper nibble if D7–D4 > 9 or CY = 1.
Differentiate between the instructions INR C and INX B with respect to operand size, instruction byte length, machine cycles executed, T-states, and their effects on the status flags.
Comparative Breakdown:
- Operand Size:
INR Coperates on a single 8-bit register (C).INX Boperates on a 16-bit register pair (BC). - Instruction Length: Both instructions are 1-byte instructions.
- Machine Cycles and T-States:
INR C: 1 machine cycle (Opcode Fetch), taking 4 T-states.INX B: 1 machine cycle (Opcode Fetch with internal bus increment), taking 6 T-states.
- Flag Register Impact:
INR C: Updates four status flags: Sign (S), Zero (Z), Auxiliary Carry (AC), and Parity (P) according to the 8-bit result. Crucially, the Carry flag (CY) is NOT affected.INX B: Modifies NO flags whatsoever (S, Z, AC, P, CY all remain untouched).
INR C increments 8-bit register C in 4 T-states and affects S, Z, AC, and P (not CY), whereas INX B increments 16-bit pair BC in 6 T-states and modifies no flags at all.
Explain how the CMP instruction works. If the Accumulator contains 62H, explain what happens to the Zero (Z) and Carry (CY) flags when the following instructions are executed independently:
CPI 62HCPI 80HCPI 45H
Operation of CMP / CPI: The instruction compares the operand with the Accumulator by performing an internal subtraction A - operand. The result is discarded, leaving the Accumulator unchanged, but the status flags are updated:
- If
A == operand:Zero flag Z = 1,Carry flag CY = 0. - If
A < operand:Zero flag Z = 0,Carry flag CY = 1(borrow required). - If
A > operand:Zero flag Z = 0,Carry flag CY = 0.
Evaluating the Three Cases with A = 62H:
CPI 62H:62H - 62H = 00H. Result is zero, no borrow. Z = 1, CY = 0.CPI 80H:62H - 80Hrequires a borrow because62H < 80H. Result is negative. Z = 0, CY = 1.CPI 45H:62H - 45H = 1DH(positive non-zero, no borrow needed). Z = 0, CY = 0.
CPI 62H: Z = 1, CY = 0 (equal).CPI 80H: Z = 0, CY = 1 (A is smaller).CPI 45H: Z = 0, CY = 0 (A is greater).
Describe the operation of the stack in the 8085 microprocessor. Explain the execution of PUSH PSW and POP PSW, detailing which flags and registers are stored in memory.
The 8085 Stack Architecture: The stack is a reserved area of read/write memory (RAM) operated on a Last-In First-Out (LIFO) basis. The 16-bit Stack Pointer (SP) stores the memory address of the current top of the stack. In the 8085, the stack grows downwards towards lower memory addresses.
Operation of PUSH PSW: PSW (Program Status Word) refers to the 16-bit combination of the 8-bit Accumulator (higher byte) and the 8-bit Flag Register (lower byte). Executing PUSH PSW:
- SP is decremented:
SP <- SP - 1. - The Accumulator contents are written to memory:
Memory[SP] <- A. - SP is decremented again:
SP <- SP - 1. - The Flag Register contents are written to memory:
Memory[SP] <- Flags.
Total 3 machine cycles, 12 T-states. Flags remain unchanged.
Operation of POP PSW:
- The byte at top of stack is read into the Flag Register:
Flags <- Memory[SP]. - SP is incremented:
SP <- SP + 1. - The next byte is read into the Accumulator:
A <- Memory[SP]. - SP is incremented again:
SP <- SP + 1.
Total 3 machine cycles, 10 T-states. All five status flags are overwritten with the restored values.
PUSH PSW decrements SP by 2, storing Accumulator at SP-1 and Flag Register at SP-2. POP PSW restores Flag Register from SP and Accumulator from SP+1, then increments SP by 2, directly updating all status flags.