COMPARE Instructions in 8085 - GeeksforGeeks

01 Nov, 2018
COMPARE is an important instruction widely used in 8085 microprocessor. The 8085 instruction set has two types of Compare operations: Compare with accumulator (CMP) and Compare immediate with accumulator (CPI).
The microprocessor compares a data byte (or register/memory contents) with the contents of the accumulator by subtracting the data byte from (A), and indicates whether the data byte is less than, greater than or equals to the content of accumulator by modifying the flags. However, the contents are not modified. The two types of COMPARE instructions are explained briefly in the following section:
Compare (register or memory) with accumulator (CMP R/M) –This is a 1-byte instruction. It compares the data byte in the register or memory with the contents of accumulator.If A less than (R/M), the CY flag is set and Zero flag is reset.If A equals to (R/M), the Zero flag is set and CY flag is reset.If A greater than (R/M), the CY and Zero flag are reset.When memory is an operand, its address is specified by HL Pair. No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.Example:Let register B contains data byte 62H and the accumulator A contains 57H. Then,Instruction- CMP B
Before execution: A = 57, B = 62
After execution: A = 57, B = 62   Flags: As A less than B, thus CY is set and Z flag is reset.CY=1, Z=0 Compare immediate with accumulator (CPI 8-bit) –This is a 2-byte instruction, the second byte being 8-bit data. It compares the second byte with the contents of accumulator.If A less than 8-bit data, the CY flag is set and Zero flag is reset.If A equals to 8-bit data, the Zero flag is set and CY flag is reset.If A greater than 8-bit data, the CY and Zero flag are reset.No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.Example:Let the accumulator A contains C2H. Then,Instruction- CPI C2H
Before execution: A = C2, B = C2
After execution: A = C2, B = C2  Flags: As A equals to the data byte, thus Z is set and CY flag is reset.CY=0, Z=1 
Compare (register or memory) with accumulator (CMP R/M) –This is a 1-byte instruction. It compares the data byte in the register or memory with the contents of accumulator.If A less than (R/M), the CY flag is set and Zero flag is reset.If A equals to (R/M), the Zero flag is set and CY flag is reset.If A greater than (R/M), the CY and Zero flag are reset.When memory is an operand, its address is specified by HL Pair. No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.Example:Let register B contains data byte 62H and the accumulator A contains 57H. Then,Instruction- CMP B
Before execution: A = 57, B = 62
After execution: A = 57, B = 62   Flags: As A less than B, thus CY is set and Z flag is reset.CY=1, Z=0 
If A less than (R/M), the CY flag is set and Zero flag is reset.If A equals to (R/M), the Zero flag is set and CY flag is reset.If A greater than (R/M), the CY and Zero flag are reset.
If A less than (R/M), the CY flag is set and Zero flag is reset.
If A equals to (R/M), the Zero flag is set and CY flag is reset.
If A greater than (R/M), the CY and Zero flag are reset.
When memory is an operand, its address is specified by HL Pair. No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.
Example:Let register B contains data byte 62H and the accumulator A contains 57H. Then,
Instruction- CMP B
Before execution: A = 57, B = 62
After execution: A = 57, B = 62   
Flags: As A less than B, thus CY is set and Z flag is reset.
CY=1, Z=0 
Compare immediate with accumulator (CPI 8-bit) –This is a 2-byte instruction, the second byte being 8-bit data. It compares the second byte with the contents of accumulator.If A less than 8-bit data, the CY flag is set and Zero flag is reset.If A equals to 8-bit data, the Zero flag is set and CY flag is reset.If A greater than 8-bit data, the CY and Zero flag are reset.No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.Example:Let the accumulator A contains C2H. Then,Instruction- CPI C2H
Before execution: A = C2, B = C2
After execution: A = C2, B = C2  Flags: As A equals to the data byte, thus Z is set and CY flag is reset.CY=0, Z=1 
If A less than 8-bit data, the CY flag is set and Zero flag is reset.If A equals to 8-bit data, the Zero flag is set and CY flag is reset.If A greater than 8-bit data, the CY and Zero flag are reset.
If A less than 8-bit data, the CY flag is set and Zero flag is reset.
If A equals to 8-bit data, the Zero flag is set and CY flag is reset.
If A greater than 8-bit data, the CY and Zero flag are reset.
No contents are modified; however all remaining flags (S, P, AC) are affected according to the result of subtraction.
Example:Let the accumulator A contains C2H. Then,
Instruction- CPI C2H
Before execution: A = C2, B = C2
After execution: A = C2, B = C2  
Flags: As A equals to the data byte, thus Z is set and CY flag is reset.
CY=0, Z=1 
microprocessor
Computer Organization & Architecture
GATE CS
microprocessor
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.
Comments
Old Comments
Architecture of 8086
Logical and Physical Address in Operating System
Computer Organization and Architecture | Pipelining | Set 1 (Execution, Stages and Throughput)
8085 program to add two 8 bit numbers
Architecture of 8085 microprocessor
Layers of OSI Model
ACID Properties in DBMS
Types of Operating Systems
TCP/IP Model
Page Replacement Algorithms in Operating Systems