PadhaikoAll subjects

8085 Instruction Set

Microprocessors (ENEX 201)

Open in the Padhaiko app

2.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:

  1. Data Transfer (Copy) Group
  2. Arithmetic Group
  3. Logical Group
  4. Branching Group
  5. 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.

Primary 8085 Data Transfer Instructions
MnemonicOperandsDescription & Micro-OperationBytesCycles (T-states)Flags Affected
MOVRd, RsMove register to register: Rd <- Rs11 (4T)None
MOVM, RsMove register to memory: [HL] <- Rs12 (7T)None
MOVRd, MMove memory to register: Rd <- [HL]12 (7T)None
MVIR, data8Move immediate byte into register: R <- data822 (7T)None
MVIM, data8Move immediate byte into memory: [HL] <- data823 (10T)None
LXIRp, data16Load 16-bit immediate data into register pair (B, D, H, SP)33 (10T)None
LDAaddr16Load Accumulator direct from memory: A <- [addr16]34 (13T)None
STAaddr16Store Accumulator direct to memory: [addr16] <- A34 (13T)None
LHLDaddr16Load H and L registers direct: L <- [addr16], H <- [addr16 + 1]35 (16T)None
SHLDaddr16Store H and L registers direct: [addr16] <- L, [addr16 + 1] <- H35 (16T)None
LDAXRpLoad Accumulator indirect through register pair BC or DE: A <- [Rp]12 (7T)None
STAXRpStore Accumulator indirect through register pair BC or DE: [Rp] <- A12 (7T)None
XCHGNoneExchange 16-bit contents of DE pair with HL pair: H <-> D, L <-> E11 (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.

Primary 8085 Arithmetic Instructions
MnemonicOperandsOperation PerformedBytesCycles (T-states)Flags Affected
ADDR / MAdd register or memory [HL] to Accumulator: A <- A + (R/M)11 (4T) / 2 (7T)All (S, Z, AC, P, CY)
ADIdata8Add immediate byte to Accumulator: A <- A + data822 (7T)All (S, Z, AC, P, CY)
ADCR / MAdd with Carry: A <- A + (R/M) + CY11 (4T) / 2 (7T)All (S, Z, AC, P, CY)
ACIdata8Add immediate byte with Carry: A <- A + data8 + CY22 (7T)All (S, Z, AC, P, CY)
SUBR / MSubtract register or memory from A: A <- A - (R/M)11 (4T) / 2 (7T)All (S, Z, AC, P, CY)
SUIdata8Subtract immediate byte from A: A <- A - data822 (7T)All (S, Z, AC, P, CY)
SBBR / MSubtract with Borrow: A <- A - (R/M) - CY11 (4T) / 2 (7T)All (S, Z, AC, P, CY)
SBIdata8Subtract immediate with Borrow: A <- A - data8 - CY22 (7T)All (S, Z, AC, P, CY)
INRR / MIncrement register or memory by 1: R <- R + 1 or [HL] <- [HL] + 111 (4T) / 3 (10T)S, Z, AC, P (CY NOT affected)
DCRR / MDecrement register or memory by 1: R <- R - 1 or [HL] <- [HL] - 111 (4T) / 3 (10T)S, Z, AC, P (CY NOT affected)
INXRp16-bit increment of register pair (BC, DE, HL, SP): Rp <- Rp + 111 (6T)None
DCXRp16-bit decrement of register pair (BC, DE, HL, SP): Rp <- Rp - 111 (6T)None
DADRp16-bit addition to HL: HL <- HL + Rp13 (10T)CY ONLY (S, Z, AC, P untouched)
DAANoneDecimal Adjust Accumulator (converts sum in A to packed BCD)11 (4T)All (S, Z, AC, P, CY)

3. Logical Group

Performs bitwise boolean operations, comparisons, rotations, and bit inversions on data in the Accumulator.

Primary 8085 Logical Instructions
MnemonicOperandsOperation DescriptionBytesCycles (T-states)Flags Affected
ANAR / MBitwise AND with Accumulator: A <- A AND (R/M)11 (4T) / 2 (7T)CY=0, AC=1, S, Z, P
ANIdata8Bitwise AND immediate: A <- A AND data822 (7T)CY=0, AC=1, S, Z, P
ORAR / MBitwise OR with Accumulator: A <- A OR (R/M)11 (4T) / 2 (7T)CY=0, AC=0, S, Z, P
ORIdata8Bitwise OR immediate: A <- A OR data822 (7T)CY=0, AC=0, S, Z, P
XRAR / MBitwise Exclusive-OR: A <- A XOR (R/M)11 (4T) / 2 (7T)CY=0, AC=0, S, Z, P
XRIdata8Bitwise Exclusive-OR immediate: A <- A XOR data822 (7T)CY=0, AC=0, S, Z, P
CMPR / MCompare with Accumulator (evaluates A - (R/M) without altering A)11 (4T) / 2 (7T)All (S, Z, AC, P, CY)
CPIdata8Compare immediate with Accumulator (evaluates A - data8)22 (7T)All (S, Z, AC, P, CY)
CMANoneOne's complement of Accumulator: A <- NOT A11 (4T)None
CMCNoneComplement Carry flag: CY <- NOT CY11 (4T)CY only
STCNoneSet Carry flag to 1: CY <- 111 (4T)CY only
RLCNoneRotate Accumulator Left without Carry (bit 7 copies to CY and bit 0)11 (4T)CY only
RRCNoneRotate Accumulator Right without Carry (bit 0 copies to CY and bit 7)11 (4T)CY only
RALNoneRotate Accumulator Left Through Carry (9-bit rotation)11 (4T)CY only
RARNoneRotate Accumulator Right Through Carry (9-bit rotation)11 (4T)CY only
CMP and CPI Condition Flags
Comparison ResultCarry Flag (CY)Zero Flag (Z)Explanation
A < Operand10Subtraction requires a borrow into MSB -> CY = 1, Z = 0.
A == Operand01Subtraction yields exactly zero (A - Operand = 0) -> CY = 0, Z = 1.
A > Operand00Subtraction 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).

  1. Unconditional Branching:
    • JMP addr16: Unconditional jump. PC <- addr16 (3 bytes, 3 cycles: OF, MR, MR = 10T).
    • CALL addr16: Unconditional subroutine call. Pushes PC onto stack, then PC <- addr16 (3 bytes, 5 cycles: OF, MR, MR, MW, MW = 18T).
    • RET: Unconditional return from subroutine. Pops return address from stack into PC (1 byte, 3 cycles: OF, MR, MR = 10T).
    • PCHL: Jump indirect. Copies HL into PC: PC <- HL (1 byte, 1 cycle: OF = 6T).
  2. 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.
  3. Restart Instructions (Software Interrupts):
    • RST n (n = 0 to 7): Pushes current PC onto stack and branches to fixed vector address (n * 8):
      • RST 0 -> 0000H, RST 1 -> 0008H, RST 2 -> 0010H, RST 3 -> 0018H
      • RST 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.

Stack and Machine Control Instructions
MnemonicOperandsOperation DescriptionBytesCycles (T-states)Flags Affected
PUSHRp / PSWPush 16-bit pair or Program Status Word (A + Flags) onto stack13 (12T)None
POPRp / PSWPop top 16-bit word from stack into register pair or PSW13 (10T)POP PSW modifies all flags; others none
XTHLNoneExchange top of stack with HL pair: L <-> [SP], H <-> [SP + 1]15 (16T)None
SPHLNoneLoad Stack Pointer from HL pair: SP <- HL11 (6T)None
INport8Read byte from 8-bit I/O port into Accumulator: A <- Port[port8]23 (10T)None
OUTport8Write byte from Accumulator to 8-bit I/O port: Port[port8] <- A23 (10T)None
EINoneEnable Interrupts (sets internal interrupt enable flip-flop)11 (4T)None
DINoneDisable Interrupts (resets internal interrupt enable flip-flop)11 (4T)None
HLTNoneHalt processor execution until hardware interrupt or reset11 (5T)None
NOPNoneNo operation (consumes 4 T-states, used for software delay loops)11 (4T)None
SIMNoneSet Interrupt Mask and Serial Output Data (SOD)11 (4T)None
RIMNoneRead Interrupt Mask and Serial Input Data (SID)11 (4T)None

Worked Examples

Example 1

1 (6 marks)

An 8085 microprocessor executes the following assembly code segment:

Text
LXI H, F000H
LXI B, 2000H
DAD B

Assume prior to execution the status flags were: S=1, Z=1, AC=1, P=1, CY=0.

  1. Compute the 16-bit value in the HL register pair after executing DAD B.
  2. Determine the status of all five flags (S, Z, AC, P, CY) following DAD B.
  3. Contrast this with the behavior of INX H on 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.
HL and Flag State After DAD B
H10H
L00H
B20H
C00H
S1
Z1
AC1
P1
CY1

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.

Answer:
  1. Final contents: HL = 1000H (H = 10H, L = 00H).
  2. Flags: CY = 1; all other flags remain untouched (S = 1, Z = 1, AC = 1, P = 1).
  3. DAD updates the Carry flag, while INX/DCX modify no flags at all.
Example 2

2 (4 marks)

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:

  1. When Accumulator contains 35H.
  2. When Accumulator contains 50H.
  3. 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) and JNC (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) and JNC (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) and JC (Jump on Carry).
Answer:
  1. A = 35H: Z = 1, CY = 0 (JZ and JNC branch).
  2. A = 50H: Z = 0, CY = 0 (JNZ and JNC branch).
  3. A = 20H: Z = 0, CY = 1 (JNZ and JC branch).
Example 3

3 (6 marks)

(Tribhuvan University Past exam questions Guide) An 8085 system initialises the Stack Pointer to 20F0H (SP = 20F0H). The CPU executes the following routine:

Text
LXI H, 1234H
PUSH H
LXI B, 5678H
PUSH B
POP H
POP B

Trace 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!
Answer:

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

Question 1

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:

  1. Data Transfer Group:
    • MOV B, M (Register Indirect Addressing Mode, 1 byte).
    • MVI A, 45H (Immediate Addressing Mode, 2 bytes).
  2. Arithmetic Group:
    • ADD C (Register Addressing Mode, 1 byte).
    • ADI 10H (Immediate Addressing Mode, 2 bytes).
  3. Logical Group:
    • ANA M (Register Indirect Addressing Mode, 1 byte).
    • CPI 50H (Immediate Addressing Mode, 2 bytes).
  4. Branching Group:
    • JMP 3000H (Direct Addressing Mode, 3 bytes).
    • JZ 2500H (Direct Addressing Mode, 3 bytes).
  5. Machine Control and Stack Group:
    • PUSH B (Register Indirect Addressing Mode, 1 byte).
    • HLT (Implicit Addressing Mode, 1 byte).
Answer:

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).

Question 2

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):

  1. 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 adds 06H to the lower nibble of the Accumulator.
  2. 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 adds 60H to the upper nibble of the Accumulator and sets the Carry flag (CY = 1).

Concrete Example (BCD Addition: 38 + 49 = 87):

  • Let A = 38H and B = 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: Since AC = 1, the processor adds 06H: 81H + 06H = 87H.
  • Final Accumulator content = 87H, which is the correct BCD sum!
Answer:

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.

Question 3

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 C operates on a single 8-bit register (C). INX B operates 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).
Answer:

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.

Question 4

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:

  1. CPI 62H
  2. CPI 80H
  3. CPI 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:

  1. CPI 62H: 62H - 62H = 00H. Result is zero, no borrow. Z = 1, CY = 0.
  2. CPI 80H: 62H - 80H requires a borrow because 62H < 80H. Result is negative. Z = 0, CY = 1.
  3. CPI 45H: 62H - 45H = 1DH (positive non-zero, no borrow needed). Z = 0, CY = 0.
Answer:
  1. CPI 62H: Z = 1, CY = 0 (equal).
  2. CPI 80H: Z = 0, CY = 1 (A is smaller).
  3. CPI 45H: Z = 0, CY = 0 (A is greater).
Question 5

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:

  1. SP is decremented: SP <- SP - 1.
  2. The Accumulator contents are written to memory: Memory[SP] <- A.
  3. SP is decremented again: SP <- SP - 1.
  4. 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:

  1. The byte at top of stack is read into the Flag Register: Flags <- Memory[SP].
  2. SP is incremented: SP <- SP + 1.
  3. The next byte is read into the Accumulator: A <- Memory[SP].
  4. SP is incremented again: SP <- SP + 1.

Total 3 machine cycles, 10 T-states. All five status flags are overwritten with the restored values.

Answer:

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.

Past exam questions for Microprocessors

← Instruction & Data Formats, Addressing Modes8085 Programs: Arithmetic, Loops, Arrays, BCD, Multiply/Divide →