Why do we need stack cleanup code and how does it work?(In assembly language) -


stack data structure follows lifo rule. in assembly language, when calling function need push arguments onto stack using "push" instruction. why need stack cleanup code remove arguments? stack cleanup code looks

add esp n 

how remove arguments stack?

i'll first answer first part of op's question: why? because cpu's, stack carries both local storage current function (local variables , arguments) , control information (return address, pointer previous stack frame, etc)

when call function not clean stack (for example, functions adhere cdecl calling convention), caller responsible leaving stack after callee returns, in same state before call. means if caller pushes n bytes stack, has remove n bytes stack, either popping , throwing them away, or faster, skipping bytes directly modifying value of stack pointer (that is, add sp,n instruction). otherwise, stack grow every called function not cleaned, , eventually, stack overflow happen.


Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -