Compare Instructions |
When the simulator does a comparison using CMP, it does a subtraction of the two values it is comparing. The status register flags are set depending on the result of the subtraction. The flags are set but the answer is discarded.
| (Z) | If the values are equal, the subtraction gives a zero result and the (Z) zero flag is set. |
| (S) | If the number being subtracted was greater than the other than a negative answer results so the (S) sign flag is set. |
| If the number being subtracted is smaller than the other, no flags are set. |
Use JZ and JS or JNZ and JNS to test the result of a CMP command.
| Assembler | Machine Code | Explanation |
| CMP CL,[20] | DC 02 20 | Here the CL register is compared with RAM location 20. Work out CL - RAM[20]. DC is the machine instruction for direct memory comparison. 02 refers to the AL register. 20 points to RAM address 20. |
| Assembler | Machine Code | Explanation |
| CMP AL,BL | DA 00 01 | Here two registers are compared. Work out AL - BL DA is the machine instruction for register comparison. 00 refers to the AL register. 01 refers to the BL register. |
| Assembler | Machine Code | Explanation |
| CMP AL,0D | DB 00 0D | Here the AL register is compared with 0D, (the ASCII code of the Enter
key). Work out AL - 0D. DB is the machine instruction for register comparison. 00 refers to the AL register. 0D is the ASCII code of the Enter key. |
© C Neil Bauers 2003