It depends on whether your atoi
function expects the pointer in %eax
or on the stack. You seem to be undecided about that, given the code segment:
movl %eax, (%esp)
call atoi
If that's supposed to be pushing the address on to the stack, you either need to really push
it (which modifies the stack pointer correctly) or modify the stack pointer yourself (such as with sub %esp, 4
or something).
The x86 stack pointer points to the last pushed entry so that push
will first decrement the stack pointer then store the value at the new pointer. That means movl %eax (%esp)
is going to corrupt the last pushed entry on the stack rather than place a new value on the stack.
Most people let the CPU handle the stacking of data rather than trying to do it manually, so you're probably looking for:
push %eax
However, if instead atoi
expects its argument in %eax
rather than on the stack, why would you write it to the stack? That's still going to corrupt whatever was there.
So, the first thing I would do would be choose either (for a pushed value):
addl $4, %eax
movl (%eax), %eax
push %eax
call atoi
or (for using %eax
), just:
addl $4, %eax
movl (%eax), %eax
call atoi