I just started reading Hacker\'s Delight and it defines abs(-231) as -231. Why is that?
I tried printf(\"%x\", abs(0x80000000))
on a f
because it uses the neg instruction to perform this operation.
In the Art of Assembly language programming book they said like this.
If the operand is zero, its sign does not change, although this clears the carry flag. Negating any other value sets the carry flag. Negating a byte containing -128, a word containing -32,768, or a double word containing -2,147,483,648 does not change the operand, but will set the overflow flag. Neg always updates the A, S, P, and Z flags as though you were using the sub instruction
source :http://www.arl.wustl.edu/~lockwood/class/cs306/books/artofasm/Chapter_6/CH06-2.html#HEADING2-313 So it will set the overflow flag and be silently.That's the reason.