CMP in assembly language

Jay Jenkins picture Jay Jenkins · Jul 19, 2012 · Viewed 10.6k times · Source

So I have this line of code:

LOOP CMP Y, #0
BEQ DONE - When it is equal go to DONE.
ADD X, #1 - add decimal constant 1 to x.
SUB Y, #1 - subtract decimal constant 1 from y
B LOOP - branch loop (start the loop again)
DONE ...

I just read that CMP means subtracting the operand from Rn (Y minus 0) And that CMN means adding the operand to the Rn (0 + Y for example)

The first line (LOOP CMP Y, #0): I thought this just compares Y with the number 0. Is this true?

Answer

Jerry Coffin picture Jerry Coffin · Jul 19, 2012

Yes -- cmp (at least in most assembly languages) does a subtraction. It sets the flags based on the result of that subtraction, but then throws away the result itself.