X86 32-bit build issue

I am currently involved in the build and I have been playing with if statements. My current code is as follows.

write: mov eax, 0x4 sub esp, 4 int 0x80 main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 je write 

If I put ret at the end of the record: then I get a bus error of 10, and if I don't get an infinite loop, which will lead to a segmentation error. What should I do to make this work?

+4
source share
2 answers

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 
+1
source

Try this instead. There is no need to call a procedure in your example.

 main: ; The message has already been pushed to the stack mov eax, 4 inc eax cmp eax, 5 jne dontwrite ; Skip Write ; Write mov eax, 0x4 sub esp, 4 int 0x80 dontwrite: ; the rest of the program goes here 
0
source

Source: https://habr.com/ru/post/1369243/


All Articles