The call
instruction itself is actually good. :)
Your problem is that you seem to forget how the AT&T syntax works. What you're doing right here with movl func, %eax
is copying a dword from the address of the label func
to the eax
register. Essentially, eax
ends up with the first 4 bytes of actual code of your function.
Immediate operands in AT&T are prefixed with a $
. The value of the func
label, being a compile-time constant can be used as an immediate and that's what you want in this case. Therefore, replace movl func, %eax
with movl $func, %eax
and you'll be alright. :)
Using lea
here is redundant. It will work, of course, but since func
is a compile-time constant, it's much more effective to simply put it as an immediate in the code instead of figuring it out at runtime.