How does a negated compare work?

  • Thread starter Thread starter Ian_Brooks
  • Start date Start date
  • Tags Tags
    Compare Work
Click For Summary
SUMMARY

The discussion clarifies the functionality of the ARM assembly instructions CMP and CMN. CMP (Compare) computes the difference between two registers, a1 and a2, and sets the NZCV flags based on the result. In contrast, CMN (Compare Negated) effectively performs a subtraction where the second operand is negated, equivalent to adding a1 and the negation of a2. This distinction is crucial for understanding conditional branching in ARM architecture.

PREREQUISITES
  • Understanding of ARM architecture and instruction sets
  • Familiarity with assembly language programming
  • Knowledge of CPU flags and their significance (NZCV)
  • Basic arithmetic operations in assembly language
NEXT STEPS
  • Study ARM assembly language instructions in detail
  • Learn about CPU flag manipulation and its impact on branching
  • Explore practical examples of using CMP and CMN in ARM programming
  • Investigate optimization techniques for conditional branching in assembly
USEFUL FOR

Assembly language programmers, computer architecture students, and developers working with ARM-based systems will benefit from this discussion.

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:

Similar threads

  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 42 ·
2
Replies
42
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 17 ·
Replies
17
Views
3K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 10 ·
Replies
10
Views
3K
  • · Replies 29 ·
Replies
29
Views
4K