Thomson
Thomson

Reputation: 21674

How to do ADD/SUB signed or unsigned integer correctly?

I saw there is an ADD instruction on ARM, does it work for both signed and unsigned int? Some status flags should be different when the instruction is specified with S suffix, right? Such as setting overflow (V) flag. I am wondering is there another version of ADD/SUB to handle one of the integer.

Upvotes: 9

Views: 11711

Answers (2)

old_timer
old_timer

Reputation: 71576

Twos complement means there is no difference between signed and unsigned addition. The s bit determines whether any flags are modified or not IF modified, then carry is the unsigned overflow/borrow and v is the signed overflow/borrow. This is all described in ARMs documentation.

Upvotes: 9

Notlikethat
Notlikethat

Reputation: 20984

Because ARM uses two's complement representation, signed and unsigned addition (similarly subtraction) are the same thing. The only difference is how you interpret the flags afterwards, if you set them with the s suffix.

Upvotes: 14

Related Questions