Chapter One computer system roaming

Source: Internet
Author: User

1.1 Information is bit + context

Include <stdio.h>int  main () {    printf ("hello,world\n");  } 

The C program source code is saved as a text file, with the name hello.c. The source code written by the programmer using the editor is a text file.

Most systems use ASCII code to represent text characters, each of which is represented as a single-byte integer value, and each word is an integer value, as shown in the first line of code. All other files are referred to as binary files.

# i n c l U d e <SPACE> < s t d i o . h >
35 105 110 99 108 117 100 101 32 60 115 116 100 105 111 46 104 62

All the information in the system--the disk file, the program in the memory, the user data in the memory, the data on the network, etc., are all represented by a string of bits. The only way to differentiate between different data is the context of the data. If the context indicates that the file is a text file, then it is as if each number corresponds to a character. If it is a binary file, for example: Images, sounds, videos, executable files, the numbers in the file represent the meaning of themselves. The same number, different file types, represents a different meaning.

1.2 programs are translated into different formats by other programs

The Hello program is executed by the computer and needs to be converted into a low-level machine language instruction. Low-level machine language instructions are made up of binary numbers.

The conversion of source code from a text file to a machine-readable binary file is done by the compiler. The compiler is also a program. The compiler conversion process is divided into four phases:

hello.c source file, preprocessor: Modified source file = hello.i (still text)
compiler = Hello.s assembler (still text) Hello.s , assembler =-linker = Hello executable (binary)

One, preprocessing phase: According to the # include <stdio.h> command will read the contents of the system header file stdio.h, insert it into the hello.c file, get the hello.i file. (Stdio.h is also c source code)

Second, the compilation phase: the C language source code translated into assembly language source code. Assembly language is a low-level machine instruction. assembly language and hardware correlation is very strong, different hardware will have different assembly language. assembly language belongs to low-level languages. In different high-level languages, the assembly language compiled by the compilers of their own languages is the same on machines on the same hardware.

The assembly phase: the assembler translates the Hello.s assembly language source code into machine instructions and packages the instructions into a hello.o (binary file). HELLO.O is a binary file, and its binary number for each byte represents a machine language instruction and does not represent a literal character. So, when you open a binary file with a text editor, it shows garbled characters.

Four, link stage: The printf function is called in hello.c. This function is a function of the standard C library that each C compiler will provide. The printf function exists in the compiled target file named PRINTF.O. With the connection, you can merge the PRINTF.O target file into the hello.o file, and finally get the Hello file, which is an executable target file.

1.3 Understanding how the compilation system works is beneficial

    • Optimize program performance. Understanding the internal workings of the compiler, we can know the different language structure of implementation, differences, so as to improve the performance of the program. For example, is a switch statement always more efficient than a series of if-then-else statements? is the while loop more efficient than a for loop?
    • An error occurred while understanding the link. The seventh chapter explains in detail
    • Avoid security breaches. Buffer overruns are the main cause of most network and Internet server security vulnerabilities. The first step in learning security programming is to understand the consequences of the way data and control information is stored on the program stack. Chapter three describes the stack principle and buffer overflow errors.

1.4 Processor reads and interprets instructions stored in memory

In Unix and Unix-like systems, the shell is a program. It is a human-computer interface, the user through the shell to the machine issued instructions. It receives the instructions entered by the user, and if the first character is not a built-in shell command, then the shell will assume that it is the name of an executable file, loading and executing the file.

Hardware composition of 1.4.1 system 

1. Bus

A bus is a group of tubes in which the parts of each computer transmit data information. The bus transmits the length of the data, is a fixed-length byte fast, called the word. The number of bytes in a word is referred to as the length, depending on the system. The word length of the 32-bit bus is 4 bytes, and the word length of the 64-bit bus is 8 bytes. The bus transmits the data is one word one word transmission, then according to the system different, the 32-bit machine can transmit 4 bytes each time, 64 bits each can transmit 8 bytes.

2.I/O Equipment

Keyboard, mouse, monitor, disk These are I/O devices. Each I/O device is connected to the bus via a controller or adapter.

3. Main memory

Main memory consists of a set of dynamic random access memory chip. Logically, the main memory each storage unit is 1 bytes, each byte has its unique address, the address starts from 0.

4. Processor

The CPU core is a word-length storage device called a program counter (PC). At any point in time, the PC points to a machine language instruction in main memory (that is, the address of the main memory where the instruction is stored).

    

  

Chapter One computer system roaming

Related Article

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.