Hello World Tour

This article documents the following for `hello.c` system running what happened once on Linux, the content comes from the first chapter CSAPP.

#include <stdio.h>

int main(int argc, char const *argv[])
{
    printf("hello, world\n");
    return 0;
}

This step can be run in the following C language program:
1. Run command line `gcc -o hello hello.c`, generating a hello executable.
`2. Enter the command line. / Hello`, the screen output hello, world information.

CPU of the computer can only run a good set some operations, such as:

  • Load: a byte or a word copied from the main memory to the CPU register
  • Storage: a byte or a word copied from the CPU registers to a location in main memory
  • Action: Copy the contents of two registers to an arithmetic logic unit ALU CPU's, these words do the ALU arithmetic operations and places the result in a register
  • Jump: extracting a word from the instruction copied to the program counter (PC) in order to cover the original value.

These operations correspond preset good machine language instructions, CPU provided not only machine language instructions and operate, the C language program needs to run it is necessary to translate the C language code into machine language instructions, and to the CPU.

The first step in the GCC compiler driver reads the source files, compiled by the system to translate it into machine language executable file.
The second step in the command line input, "Hello" characters one by one will be read into the CPU registers, and then store it into the main memory ; when the carriage on the keyboard, the command-line shell will be invoked by the operating system command execution file, when calling the executable file, the file will first hello first copied from disk to main memory, and an instruction file hello eleven read and executed by CPU , finally generated "hello, world" string from the CPU register is copied to the main memory, and output to the screen.

Guess you like

Origin www.cnblogs.com/ysfdm/p/11443338.html