1
\$\begingroup\$

as an exercise problem in ARM assembly program, I had to convert a number x to its absolute value. now seeing the problem as a simple problem of removing the sign of the respective number, I used BIC instruction to clear the MSB sign bit. later on I found out that RSBMI instruction is present in ARM to compute the absolute value of any number.

my query is that what is the difference between these two methods employed, does BIC and RSBMI present any different result in some cases? or if it can be done by just BIC then why add an RSBMI in RISC instruction set?

\$\endgroup\$
1
  • \$\begingroup\$ Your BIC would work if values were represented as sign-magnitude. Instead (nearly?) all computers use 2's-complement. \$\endgroup\$ Commented Jul 20, 2014 at 9:37

1 Answer 1

4
\$\begingroup\$

I had to convert a number x to its absolute value. now seeing the problem as a simple problem of removing the sign of the respective number

Which yields wrong results, of course. Example (in 8 Bit): -1 = 0xFF, sign bit set to zero: 0x7F => +127 instead of +1.

\$\endgroup\$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.