I had some problems with the sample code that I tested, since my abs function did not return the correct result. abs (-2) output -2 (this, by the way, is considered a function of the absolute value, if it was unclear)
After a little despair, I finally got the following code
#include <stdio.h>
unsigned int abs(int x) {
return 1;
}
int main() {
printf("%d\n", abs(-2));
return 0;
}
This is nothing useful, but it serves to demonstrate my problem. This printed -2 when output 1 was expected.
if I change the name of the function to something else (e.g. abs2), the result is now correct. In addition, if I change it to receive two arguments instead of one, it will also fix the problem.
: . , -2 ( 2, abs). ( abs abs2)
:
23,25c23,25
< .globl abs
< .type abs, @function
< abs:
---
> .globl abs2
> .type abs2, @function
> abs2:
54c54
< .size abs, .-abs
---
> .size abs2, .-abs2
71c71,74
< movl -4(%rbp), %edx
---
> movl -4(%rbp), %eax
> movl %eax, %edi
> call abs2
> movl %eax, %edx
, , ( abs) , x abs (x)
, : , , - .
Squeeze Debian, ggc 4.4.5, gcc 4.1.2