In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces the relevant knowledge of "what is the method of compiling computer system source programs". The editor shows you the operation process through actual cases, and the operation method is simple, fast and practical. I hope this article "what is the method of compiling computer system source programs" can help you solve the problem.
Information in a computer
For programmers, HelloWorld programs are all too familiar. Here are HelloWorld programs written in C language.
# include
Int main ()
{
Printf ("hello, world\ n")
Return 0
}
This program is very simple, just output hello world on the screen, it is easy for programmers to read, but from a computer point of view, is it that simple?
As we all know, the computer world has only 0 and 1 bits, which is so unfriendly to human beings that computer scientists have designed ASC Ⅱ codes to represent symbols of the real world. Every 8 bits form a group (called a byte), with a group to represent a symbol, the above C program represented by ASC Ⅱ is the following style.
So for a computer, all data is represented by a string of bits, and the only way to distinguish these data objects is the context in which they are read.
Information = bit + context
Source program compilation
Although we have finished writing the C language program, it can not run, because it is only a text file made up of ASC Ⅱ characters, and the computer can not run the text file.
If you want to get the executable file of HelloWorld, you need to go through four stages: preprocessing, compilation, assembly and linking.
In the preprocessing stage, the preprocessor will modify the source program according to the command that begins with the character #. The preprocessor reads the contents of the system header file stdio.h and inserts it directly into the program text, resulting in another C program-hello.i.
In the compilation phase, the compiler will translate the hello.i program into the assembly language program hello.s, which is essentially a machine language, and the program is still a text file.
During the assembly phase, the assembler translates the hello.s into machine language instructions, saves it in the hello.o file, and gets the binary file.
The program uses the printf function, which is a function in the standard C library provided by the compiler, which is stored in the printf.o file, which the linker merges into hello.o, resulting in an executable hello file that is stored on disk.
System composition and program operation
Before running the executable hello file, you should understand the hardware composition of the system. The hardware organization of a typical system is shown in the following figure.
In order to run the hello program, we need to enter the instruction. / hello in the shell. The instruction is stored in main memory via the keyboard via the Imax O bus-- > Imax O Bridge-- > bus interface-- > register-- > Imax O bridge. When you hit the enter key, you will tell the shell program that the command belongs to the end, and shell will execute a series of instructions to load the hello file.
Using direct access (DMA) technology, hello files can reach main memory without going through registers. When the target file hello arrives in main memory, the processor begins to execute the machine instructions of the hello program. The instruction is to copy the bytes of the "hello, world\ n" string from the main memory to the register, then from the register to the display device, and finally display it on the screen.
We find that this simple HelloWorld program will make the system spend a lot of time moving information from one place to another, and we all know that the access speed of registers, main memory and disks is several orders of magnitude lower than each other, and the cost of replication will seriously slow down the program. In order to speed up these replication operations, system designers have introduced caching.
The importance of abstraction
One of the most important concepts in computer science is abstraction. Instruction sets provide abstraction of hardware processors. Operating systems also provide applications with simple and consistent mechanisms to control low-level hardware devices through the abstract concepts of processes, virtual memory, and files (disks, keyboards, networks can all be regarded as files), while preventing hardware from being abused by out-of-control applications.
A process is an abstraction of a running program. Multiple processes can be run at the same time on a system, but each process seems to be using hardware exclusively. CPU seems to be executing multiple processes concurrently, which requires the operating system to switch contexts.
Before we entered. / hello, only the shell process was running, and when we asked it to run the hello program, shell would execute our request through a system call. The operating system first saves the context (PC, registers, etc.) of the shell process, then creates a new hello process and transfers control to the hello process.
This is the end of the content about "what is the method of compiling computer system source programs". Thank you for your reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.