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\$
  • \$\begingroup\$ Your BIC would work if values were represented as sign-magnitude. Instead (nearly?) all computers use 2's-complement. \$\endgroup\$ – Wouter van Ooijen Jul 20 '14 at 9:37
3
\$\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, privacy policy and cookie policy

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