9 ms·
I find this article somewhat lacking a lot of content, given the amount of information you've been given in the gist and available on the internet. Anyway, the
by omegote 13y ago
I find this article somewhat lacking a lot of content, given the amount of information you've been given in the gist and available on the internet.
Anyway, the answer to your "What happens when you run 'Hello, world'" should be divided in two parts.
First, the most important part (in my opinion) is understanding how the compiler translates the C code into assembly. Listing the assembly code of your program in your post is a must. GCC does a damn good job in generating readable assembly output, if you know which flags to use. In order to get just the important stuff, you could use:
cc -S -m32 -fno-asynchronous-unwind-tables main.c -o -
Now you should try to understand what does what. Knowing what the EBP and ESP pointers do is the absolute minimum, because they handle the stack. Also, it's important to understand how parameters are passed using both registers and memory positions, because that's how the system call (and any other function) is going to receive the reference to the string.
Now that you know what the program is intended to do (as per its instructions), the next thing to learn is how the program (its data and instructions) gets loaded in the memory and passed to the processor. Two things involved here: the shell (not the kernel) that reads your command and launches your executable, and (now yes) the kernel executing your program, previously building all the necessary memory structures.
The level of detail you want to go into can be very different. Do you need to know how the shell reads your "./main" command? Do you want to know how the executable is launched using fork-exec? There's a lot involved at this point. You should set your "detail level" and from that point, investigate.
- rajeevk 13y agoHere is an article (by me) to understand how various c-constructs are translated into assembly http://www.avabodh.com/cin/cin.html http://www.avabodh.com/cin/cin.html