How does a negated compare work?

  • Thread starter Thread starter Ian_Brooks
  • Start date Start date
  • Tags Tags
    Compare Work
AI Thread Summary
In ARM architecture, the CMP instruction compares two values by calculating the difference and setting the NZCV flags accordingly. The CMN instruction, on the other hand, compares the first operand to the negated second operand, effectively performing an addition instead of a subtraction. This means CMN can be viewed as a comparison that checks if the first operand is greater than the negation of the second. The primary benefit of using CMN lies in its ability to simplify certain branching operations. Understanding these differences can enhance efficiency in coding and decision-making processes in ARM assembly language.
Ian_Brooks
Messages
127
Reaction score
0

Homework Statement



I understand that in the ARM architecture
CMP a1, a2

will take the difference between a1 and a2 and make a decision based on its flags
NZCV - if the difference is positive a1 > a2, and vice versa

But how does a negated cmp work?

CMN a1, a2 ?

Is it the opposite?


Homework Equations





The Attempt at a Solution



see above. the internet gives me nothing
 
Physics news on Phys.org
CMP means Compare values
CMN means Compare Negated values

The ARM instruction sets are widely published, but here is a link to a help page

http://www.heyrick.co.uk/assembler/cmp.html#cmn
I am sure you will be able to figure it out from there.
 
Last edited:
thanks for the link -

If
cmp a1, a2 ; performs a subtraction
cmn a1, a2 ; performs a subtration with the second opperand being negative or
...;a1-(-a2) so its the same as an add, so what's the benefit of using cmn besides branching?
 
Last edited:
Back
Top