The call
and ret
instructions (and probably int
) implicitly use the stack, and therefore require esp
to point to the correct location (i.e. the current top of the current thread's stack; or the current top of some stack that you've set up yourself). Since you're using esp
as a general-purpose register in your code you end up accessing memory locations that your application most likely doesn't have access to as soon as you execute e.g. a call
:
mov esp,[nums+esi]
call ptln ; call tries to push the return address onto the stack, but esp
; now contains one of the values from nums: OOPS! -> segfault
Rule of thumb: Do not use esp
as a general-purpose register unless you're really, really sure that it's ok to do so.
Another potential problem is that nums
is accessed as if it was an array of doubleword, even though it's declared as an array of bytes.