What is “the stack”?
&gt; I found it pretty surprising that the x86 assembly instruction set knows about the C stack pointer and how the stack in C is laid out. Of course, you could invent your own new smart stack format, but you wouldn&#x27;t be able to use the callq and retq instructions to call functions.<p>I find it pretty amazing how modern &quot;programmers&quot; are lacking in knowledge of basic computer science concepts. Let me nit-pick this statement as it is obviously wrong.<p>The x86 assembly language knows <i>ABSOLUTELY</i> nothing about the &quot;C stack pointer and how the stack in C is laid out&quot;. I will now illustrate why the first part of this statement is wrong.<p>You can have a bare-metal x86 device that is only programmed though assembly and push&#x2F;pop would still be available. You are clearly confusing the roles of the compiler, operating system, and the language your program is written in. On a modern operating system like Linux, each program, when started, runs in a new process, which has its own view of memory due to the virtual memory system. Each program has its view of memory split into several sections, and one of them is allocated as &quot;stack space&quot; (it&#x27;s usually the high memory addresses but this is architecture and&#x2F;or OS dependent). When the program is executed, %rsp would be set-up appropriately by the OS, and on context switches it would save&#x2F;restore it. Moreover, the actual address of your stack in real memory is different for every program since each process&#x2F;program has its own mapping of virtual to physical memory, again provided by the OS.<p>Now, the second part about the &quot;layout of the stack&quot;. The language you write your program in (in this case C) knows <i>ABSOLUTELY</i> nothing about the layout of &quot;the stack&quot;. However, when you give your source code to the compiler, it will analyse it and, because C is low-level and staticly typed, will infer <i>HOW</i> it actually needs to lay out the stack <i>FOR you</i>. The output of the compiler is assembly code, and the assembly code produced &quot;knows&quot; about the layout of the stack because it has been written that way, generated by the compiler. It is, actually, the compiler that knows about all of this, not the source or assembly language.<p>Also, the example with python was a bad one - python is an interpreted language, and AFAIK it has no concept of a stack, and even if it does, it is the interpreter that allocates frames for it&#x27;s own computations, not the program that you are running. And, moreover, even if python does allocate stack frames, they are most probably on the heap since it needs to do so dynamically (again, since it&#x27;s not compiled but interpreted).