title: How are stacks in windows x86 stack defined?
body: <p>First I'm going to demonstrate a poor understanding of the stack, and then I'm going to ask a mildly coherent question that can't be answered well because the question isn't specific enough to elicit a well-composed answer.</p>
  
  <p>So, when a program runs functions are pushed to the stack - this means the stack pointer is incremented or decremented?</p>
  
  <p>What exactly is stored in the stack memory allocation? Pointers to variable data, pointers to the est of the program? I just don't understand what exactly is stored on the stack (what data types, what kinds of references, how they ae stored) I expect a function stores its local variable pointers and a pointer to the address that called it so it can return.</p>
  
  <p>Also, windows x86 virtual memory allocation actually maps a single block of virtual memory to arbitrary many physical memory addresses, so a stack is or is not contiguous in the physical memory of a windows x86 system?</p>
  
  <p>Finally, assuming a stack is stored in the user-allocated virtual memory of an application on 32-bit windows on x86, the stack pointer (which references the high or low memory address?) is a 31-bit (31 because user-allocated and the high 2GB are reserved for kernel allocated) little-endian reference, right?</p>
  
  <p>And when data reaches the stack (like a function is entered and allocates memory for a new DWORD) the data to store in that DWORD is pushed to the stack and the stack pointer is incremented or decremented? And how is the system aware of both ends of the stack simultaneously?</p>
  
  <p>---- ESP HERE?</p>
  
  <p>|-reference address for variable x</p>
  
  <p>|-integer data to be stored in the memory address of variable x in function 1</p>
  
  <p>|----function 1 block above ^^</p>
  
  <p>|</p>
  
  <p>|</p>
  
  <p>---- OR ESP HERE?</p>
  
  <p>And from here the reference address and integer data will be popped into registers, and a mov operation will store the integer data at the allocated memory location?</p>
  
  <p>When new data hits the stack, I've heard the stack grows "downward" but that seems irrational since there are only higher and lower memory addresses - I understand that only one end of the stack needs to be incremented/decremented, but is it the high or the low address, and how is the stack length(height) delimited? How does the system understand when the stack has "grown" too large?</p>
  
  <p>Sorry for all the questions, but I've been doing a lot of reading, and the terminology used to describe the concepts I've been reading about aren't well operationalized in my vocabulary. Also I checked a bit around google, wikipedia, and this site and couldn't find an explanation that addressed my specific concerns.</p>
  
  <p>Thanks.</p>