4 ms·
What happens when you run "Hello, world"
- omegote 13y agoI 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
- revelation 13y agoI'm confused. Do you want to understand what happens when you run a program or are you interested in replicating all the things to create a semi operating system of your own? You could probably expand a lot on systemcalls.
- jheriko 13y agoi'd recommend looking at how this works as a very tiny com file... its a bit out of date but reveals a lot about how an OS can choose different ways to achieve this, including how it can implement system calls differently and how simple an executable loader used to be... http://stackoverflow.com/questions/284797/hello-world-in-less-than-20-bytes http://stackoverflow.com/questions/284797/hello-world-in-les...