Affected Flags |
|||
C | V | N | Z |
X | X |
X | X |
cmp | : compare two registers |
The cmp instruction make a comparison between two registers and the status flag is set accordingly. Internaly, the cmp instruction works by substrating the first register to the second register, the result is not stored, only the flags are set.
To use the result stored in flags, you can use one of the Bxx instructions.
ry = Source register 1
rx = Source register 2
Form | Effect |
cmp.b ry,rx |
Compare rx and ry Set the status flags |
cmp.w ry,rx |
|
cmp.l ry,rx |
S = Source register 1
D = Source register 2
Instruction | Op Code |
Cycles | Encoding |
cmp.b ry,rx | 1A | 6 | 00011010 SSSSDDDD |
cmp.w ry,rx | 5A | 6 | 01011010 SSSSDDDD |
cmp.l ry,rx | 9A | 6 | 10011010 SSSSDDDD |
// Example : Compare two numbers
; r0 = number 1
; r1 = number 2
start: cmp.l r0,r1
beq equal
bne notequal
equal: ; do something, numbers are equal
notequal: ; do something, numbers are not equal