How get two's complement of a register value in ARM?
10,463
Try this, (MVN move with negate):
MVN v2, v1
This "flips the bits" like you asked. Then you just do the +1:
ADD v2, v1, #1
Alternatively you can just use the NEG v2, v1 instructions (a synonym for RSB v2, v1, #0) to do the equivalent operation in a single instruction.
Author by
Anthony Elliott
Updated on June 04, 2022Comments
-
Anthony Elliott almost 2 years
Say I have a 32 bit signed int in register v1. I want to get the two's complement of this value to store in another register v2. In normal math that means I need to flip all 32 bits and then add 1.
How do I flip the bits?
Thanks in advance.