Computer system Learning Notes (1)-hello World's life.

Source: Internet
Author: User

#include <stdio.h>int main () {    printf ("Hello world\n");}

The above is a C-language Hello World program, although the return 0 is missing, but this does not affect the theme of this article. The above HELLO.C program is in a series of bytes (1byte = 8bits) Form in the file, each byte has an integer value, corresponding to a character, and this integer value is called ASCII code, a file consisting of ASCII code is called text files. The rest of the file is called binary files.

The program is translated into different forms by other programs:

The source program hello.c (text) will first be modified by the preprocessor to hello.i (text), for example: the preprocessor will #include<stdio.h> according to the instructions, the contents of the Stdio.h header file inserted directly into the file.

The modified hello.i is then compiled by the compiler into HELLO.S (assembly language text).

HELLO.C is then compiled by the assembler compiler to HELLO.O (machine language binary)

Finally, because the function has the printf () function, the function belongs to the C standard library, the function is called PRINTF.O in a separate precompiled file, to generate the executable file, must be linker (connector) HELLO.O and The PRINTF.O file is linked together, and the executable hello is generated at the end.

How do you perform the above process?

In my Mac OS system, first open the terminal (terminal), then in the terminal with the CD command to navigate to the current file location, and then enter Gcc-o Hello hello.c in the terminal to complete all of the above compilation process, and generate the executable file Hello, Note: In this statement, Gcc-o Hello hello.c in the middle of the hello represents the name of the generated executable file.

How do I run an executable file?

After completing the above steps, you only need to enter the./hello to print out Hello World on the terminal, or you can double-click the amount of executable file to complete the operation.

How do you run executables in our computer?

A computer generally consists of the following parts:

1. CPU (central processing Unit), can also be called processor.

Mainly by: Register file, PC (program counter), ALU (Arithmetic/logic Unit), USB (Universal Serial Bus) composition, the main functions are:

Executes instructions that are stored in memory. Its core is a storage device (or register) with word-sized (a word size) as the basic unit, called Program Counter (PC) , at any point in time, the PC points to an in-memory instruction, When the current instruction is executed, the PC moves to the next instruction.

2. Main memory (RAM)

Memory is a temporary storage device, when the CPU is running, memory is used to temporarily store programs and data, when the program executes, these programs and data are erased by memory,

3. Buses (transmission line)

Buses is the line used to transmit data, buses can transfer fixed-size words, a word bytes on different machines, some 4bytes (32bits), some 8bytes (64bits), and we assume buses Transfer one word at a time.

4. I/o Devices (input)

< Span style= "Font-family:comic Sans MS" > input is a bridge between the system and the outside world, common I/O devices: Keyboard, mouse, screen, disk.

each I/O device is passed through a controller or adapter (adapter) and i/ O bus connection, wherein the controller and adapter the main difference is that the controller is mainly directly on the motherboard (main printed circuit board) above, and adapter is a card inserted in the motherboard.

and then back to the point, what is the process of running the executable file on the computer?

The shell program (shell) is executing the "Wait for us to enter" instruction when we type "./hello" in the terminal before entering./hello. Program reads each character through the bus into the register in the CPU, and then stores the instruction in memory.

When we type "enter", the shell knows that we have finished typing, so we execute a series of instructions to copy the code and data from our executable hello to the memory (disk).

When code and data in Hello are loaded into memory, the CPU (processor) starts executing a series of machine instructions in main, and the string "Hello, world\n" is copied to the register file by instruction, and eventually transferred to the output device----screen.

Computer system Learning Notes (1)-hello World's life.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.