COMPARE Instructions in 8085

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:

  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.



    1. If A less than (R/M), the CY flag is set and Zero flag is reset.
    2. If A equals to (R/M), the Zero flag is set and CY flag is reset.
    3. 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 
  2. 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.

    1. If A less than 8-bit data, the CY flag is set and Zero flag is reset.
    2. If A equals to 8-bit data, the Zero flag is set and CY flag is reset.
    3. 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 


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.