Use the call command instead of je to enter write . ret expects the return address to be on the stack, but it will not be pressed if you use a jump to get there! You will need to put esp back into what it was when you entered the function. Here is an example of best guessing based on your code:
write: mov eax, 0x4 sub esp, 4 int 0x80 add esp, 4 ret main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 jne dontwrite ; skip calling 'write' if eax != 5 call write dontwrite: ; the rest of the program goes here
source share