I compiled the following C language program with clang (clang is 3.4-1ubuntu3, OS is Ubuntu Ubuntu 14.04.5 on AWS, 32bit).
sample.c
#include <stdio.h>
int func(int a, int b)
{
return a + b;
}
int main()
{
int x = 1;
int y = 2;
int c;
c = func(x, y);
printf("%d\n",c);
return 0;
}
This is an excerpt of the result of disassembling the code compiled with clang with objdump -d.
objdump.s
8048464: 89 4c 24 04 mov %ecx,0x4(%esp)
8048468: e8 b3 ff ff ff call 8048420 <func>
804846d: 8d 0d 30 85 04 08 lea 0x8048530,%ecx
8048473: 89 45 f0 mov %eax,-0x10(%ebp)
8048476: 8b 45 f0 mov -0x10(%ebp),%eax
What I would like you to know is mov %eax,-0x10(%esp) After mov -0x10(%esp),%eax Is why you need it. The value of the eax register hasn't changed, so I feel it's unnecessary. Is there any special reason? By the way, even if I compile it with gcc, the generated code was similar. If you are an expert, I would appreciate it if you could tell me.
Recommended Posts