Should I clear the stack when I call the exit function from the assembly?

I was asked to create a small program in the assembly using the functions of C. At the same time, I was interested to learn something specific.

I know that when working with the assembly, wherever I want to call the C function, I have to push its arguments to the stack, and after the function returns, I have to put these arguments (or add 4x times to esp, where x represents the number of pressed arguments).

My question is: When calling the C function exitin particular, I must first press the argument for the state. Let's say I want to press 0 to indicate that my program worked without errors.

Knowing that the function exitdoes not return and that I have to use it and cannot simply cause the interruption of the exit system, how can I pull this out of the stack in this case? Does the function exitdo this for me?

+4
source share
1 answer

You don’t have to. Since it exit()does not return and the program terminates, the system frees up all the memory you use, including the stack.

Note that the compiler will generate add esp, 4to clear the stack, because the compiler does not know that it exitwill never return.

+1
source

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


All Articles