CMP

 

Syntax: CMP R
Where R can be any of the general purpose registers (A,B,C,D,E,H and L)
Byte: 1byte
Addressing Mode: Register Addressing

Working: 
1. This is one byte instruction.
2. microprocessor will allocate one byte for opcode CMP and operands are registers i.e. operands don't need memory allocations for execution here.
3. This instruction compares the content of the register R with content of the Accumulator.
The comparison is done using subtraction of the content of register from the Accumulator
The content of Accumulator remains unchanged.
Conditions of Comarison:
 
1.  If [A] < [R] then Cy flag is set i.e. Cy =1.
2. If [A] = [R]  then Z flag is set i.e Z=1.
3. If [A] > [R]  then Cy and Z flags are reset. i.e Cy = 0 and  Z = 0
4. Flag

Example: CMP B
where [B] = 22H 
and [A]= 11H
After execution of CMP B
[A] = 11H
[B] = 22H
 

2's complement subtraction:
A= 11 =  0001 0001
B= 22 =  0010 0010
1's complement of B = 1101 1101
2's complement of B =  1101 1110
 
                                1
                  A =    0001 0001
 2's copm. B =    1101 1110
                      0  1110  1111 
 
Cy = 1..............[complement the carry (according to 2's complement subtrsction)]
Z =  0

 
First condition of comparison is matched. i.e. [A]< [B]

Comments