Purpose
Compare the 8-bit contents of the accumulator (A) with the contents of another register or a memory location without changing either operand. All the flags are updated so that the result of the comparison can be tested with a conditional jump/call/return.
Mnemonic & Forms
CMP R ; R = B, C, D, E, H, L, or A
(1-byte, 4 T-states)
CMP M ; Compare with the byte pointed to by HL
(1-byte, 7 T-states)
⚠️ 8085 does not have an immediate compare (that exists in 8086, not 8085). To compare with an immediate value you usually do:
MVI B, data
CMP B
Internal Operation
A – (operand) → result not stored, flags only
Flag effects (after A – operand):
• Z = 1 if A == operand (equal)
• CY = 1 if A < operand (borrow generated)
• S, P, AC also follow the subtraction result (rarely used for compare decisions)
Decision guide
Result | Z | CY | Meaning
Equal | 1 | 0 | A = operand
Greater (A>op) | 0 | 0 | A > operand
Smaller (A<op) | 0 | 1 | A < operand
Typical usage pattern
asm
LHLD 2000H ; HL points to data in RAM
MOV A, M ; A = first number
INX H
MOV B, M ; B = second number
CMP B ; Compare A with B
JZ EQUAL ; If Z=1 → A == B
JC LESS ; If CY=1 → A < B
JMP GREATER ; Otherwise A > B
EQUAL: ; … handle equality …
LESS: ; … handle smaller case …
GREATER: ; … handle larger case …
Practical hints
• CMP does NOT save the result—if you need it later, do a SUB and save, or push/pop A before CMP.
• After CMP, use conditional branch instructions (JZ, JNZ, JC, JNC, JP, JM) while the flags are still valid; any arithmetic/logic instruction in between will overwrite the flags.
• For looping (e.g., count down to zero), CMP M / JMP can be faster than using INR/DCR plus JZ.
Example – find the larger of two numbers stored at 2200H & 2201H and store it at 2202H:
asm
LDA 2200H ; A = first number
MOV B, A ; Save in B
LDA 2201H ; A = second number
CMP B ; Compare second (A) with first (B)
JC FIRST ; If A < B, first number is larger
; else A >= B
STA 2202H ; store second number (A) – it’s larger
HLT
FIRST:
MOV A, B
STA 2202H ; store first number (B) – it’s larger
HLT
Summary
CMP in 8085 is a one-byte compare-only instruction that performs A – operand, updates all flags, keeps the operands unchanged, and is immediately followed by a conditional branch to check for equal, greater, or smaller conditions.