This question is asked because the author is building a compiler (src -> asm) and is in the process of writing code for generating assembly code.
One of the first things that happens when a program executes on a Linux (any OS really) based operating system is that the stack gets set up and the SP register is assigned with the memory address of the beginning of the stack.
I was curious about if the responsibility of doing the above lies with the program, or the OS itself. If it is the case that the responsibility lies with the program, how is this accomplished by the program (specifically, in a Linux base environment)?
What other actions must an individual program do before it can start executing its main function?
Examples with commented i386 NASM assembly code is appreciated. Also, any web resource that could help the author in his goal would also be very much appreciated.