CHAPTER 1 ----- a tour of computer sysytems(1)

1.1Information is bits + context.

  All information in a system——including disk files,programs stored in memory ,user data stored in memory ,and data transferred across a network——is represented as a bunch of bits.The only thing that distinguished different data objects is the context in which we view them.

  系统中所有的信息——包括磁盘文件,内存中的程序,内存中存放的用户数据以及网络上传送的数据——都是由一串比特表示,区分不同数据数据对象的唯一方法是我们读到这些数据时的上下文。

  For example, in different contexts,the same sequence of bytes might represent an integer, floating-point number,character string ,or machine instruction,

  A source program (hello.c) is a sequence of bits,each with a value of 0 or 1 ,organized in 8-bits chunks called bytes.Most modern systems represent text characters(文本字符)using ASCII standard that represents each character with a unique byte-sized integer value.

  The hello.c program is stored in a file as a sequence of bytes.Notice that each text line is terminated by the invisible newline character ' '(which is represented by the integer value 10). Files(文件) such as hello.c that consist exclusively(唯一的) of ASCII character are know as text files(文本文件).

 include<stdio.h>

int main()

{

  printf("hello world ");

}

1.2 Programs are translated by other progrems into different forms

hello.c can be read and undertand by human beings.In order to run hello,c on the system,the individual C statements must be translated by the compiler driver into a sequence of machine-language instruction.These instructions are then packaged in a form called an executable object program and stored as a binary disk file.

预处理器:preprocessor(cpp);编译器:compiler(cc1);汇编器:assembler(as);链接器Linker(ld);

Preprocessor phase(预处理阶段).The preprocessor(cpp)modifies the original C program accroding to directives that begin with the # character.Eg:insert stdio.h directly into the program text and the result is another C program,typcally with the .i suffix(后缀).

Compilation phase.The compiler(cc1)translates  the text file hello.i into hello.s,which contains an assembly-language program.Eg:hello.s contains the definition of function main:

each statement(2-7) in an assembly-language program exactly describes one low-level machine-language instruction in a standard text form.Assembly language provides a common output language for different compilers for different high-level languages.

Assembly phase.the assembler(as) translates hello.s into machine-language instructions,pachages them in a form known as a relocatable object program(可重定位目标程序),and stores the result in the object file hello.o.The hello.o file is a binary file whose bytes encode machine language instruction rather than charaters.If we  were to view hello.o with a text editor ,it would appear to be gibberish(乱码).

Linking phase.The linker(ld) handles this merging,which merge printf.o (because of the function printf) with our hello.o.The result is the hello file,which is an executable object file  that is ready to be loaded into memory  and executed by the system.

  

原文地址:https://www.cnblogs.com/SsoZhNO-1/p/8822213.html