#define ESP
(rel,value,addr) \
asm volatile ("mov (%%esp, %2, 4), %0\n
\t" \
"lea (%%esp, %2, 4), %1\n
\t" \
: "=r" (value),
"=r" (addr) \
:
"r" (rel)); \
It didn't work as expected so I looked at the assembler code generated
for the above:
1: b8 00 00 00 00 mov $0x0,%eax
2: 8b 04 84 mov (%esp,%eax,4),%eax
3: 8d 14 84 lea (%esp,%eax,4),%edx
4: 89 45 f8 mov %eax,0xfffffff8(%ebp)
5: 89 55 fc mov %edx,0xfffffffc(%ebp)
As it turns out, %eax is being used for both input and output in line
2, clobbering %eax, so of course line 3 does not give the expected
result... Is this a compiler error?