How does a negated compare work?

In summary, the conversation discusses the ARM architecture and the use of CMP and CMN instructions. CMP compares two values and makes a decision based on the flags NZCV, while CMN compares a value with its negated version. The conversation also mentions the benefits of using CMN, such as branching.
  • #1
Ian_Brooks
129
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
  • #2
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:
  • #3
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:

FAQ: How does a negated compare work?

1. How does a negated compare work?

A negated compare is a type of comparison operation that evaluates whether two values are not equal to each other. It is used in programming to check for inequality between two values, and the result of the comparison is either "true" or "false".

2. What is the syntax for a negated compare in programming?

The syntax for a negated compare varies depending on the programming language, but it typically involves using the exclamation mark (!) followed by the equal sign (=). For example, in JavaScript, the syntax would be "!==", while in Python it would be "!=".

3. How does a negated compare differ from a regular compare?

A regular compare, also known as an equal compare, checks if two values are equal to each other. A negated compare, on the other hand, checks if two values are not equal to each other. This means that the result of a regular compare can only be "true" or "false", while the result of a negated compare can also be "null" or "undefined" if the values being compared are not of the same type.

4. Can a negated compare be used with all data types?

Yes, a negated compare can be used with all data types, including numbers, strings, booleans, and objects. However, as mentioned before, the result of the comparison may vary depending on the data types being compared.

5. When should a negated compare be used?

A negated compare is commonly used in conditional statements, where a certain block of code should be executed only if two values are not equal to each other. It can also be used in filtering or sorting data, as well as error handling in programming.

Back
Top