how does push and pop work in assembly
The latter POP EBP is equivalent to MOV EBP, [ESP] ADD ESP, 4 ; but without modifying flags, like LEA ESP, [ESP+4] (in Intel syntax – target on the left, source on the right)
The latter POP EBP is equivalent to MOV EBP, [ESP] ADD ESP, 4 ; but without modifying flags, like LEA ESP, [ESP+4] (in Intel syntax – target on the left, source on the right)
The shadow space must be provided directly previous to the call. Imagine the shadow space as a relic from the old stdcall/cdecl convention: For WriteFile you needed five pushes. The shadow space stands for the last four pushes (the first four arguments). Now you need four registers, the shadow space (just the space, contents don’t … Read more
I found the answer provided by greyfairer is wrong. The JVM runtime does not gather the root set from stack by looking at what bytecodes are used to push data on the stack. The stack frame consists of 4 byte(32bit arch) slots. Each slot could be a reference to a heap object or a primitive … Read more
I’m not entirely sure what you’re asking, but I’ll try my best to answer. The following declares a variable i on the stack: int i; When I ask for an address using &i I get the actual location on the stack. When I allocate something dynamically using malloc, there are actually TWO pieces of data … Read more
Here is what the book says on page 205: If you’re familiar with operating system architecture, you might be interested to know that local variables and function arguments are stored on the stack, while global and static variables are stored on the heap. This is definitely an error in the book. First, one should discuss … Read more
I think that you are confusing “stack/heap allocation” and “automatic variable”. Automatic variables are automatically destroyed when going out of context. Stack allocation is the fact that the memory is allocated on the execution stack. And variable allocated on the stack are automatic variables. Also, members are automatic variables whose destructors get called when its … Read more
No, not in general. Do you know of gcc -fsplit-stack ? It is up to the implementation to decide whether to allocate a contiguous stack or a stack where blocks are interleaved with heap blocks in memory. Good luck figuring out whether a block was allocated for the heap or the stack when the latter … Read more
One trick, which is not portable or really even guaranteed to work, is to simple print out the address of a local as a pointer. void print_stack_pointer() { void* p = NULL; printf(“%p”, (void*)&p); } This will essentially print out the address of p which is a good approximation of the current stack pointer
you cannot change the address of an array. It will give a compile time error. have a look: http://codepad.org/skBHMxU0 EDIT: the comments made me realize your true intent: something like: char *ptr = “one two three”; ptr++; There is no problem with it. the string “one two three” is a constant, and you can freely … Read more
_chkstk does stack probes to make sure each page is touched in order after a (potentially) large allocation, e.g. an alloca. Because Windows will only grow the stack one page at a time up to the stack size limit. Touching that “guard page” triggers stack growth. It doesn’t guard against stack overflow; I think you’re … Read more