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

本文深入探讨了信息在计算机系统中的表示方式,指出所有信息本质上是由比特组成,并通过上下文来区分不同的数据对象。此外,详细介绍了从源代码到可执行程序的编译过程,包括预处理、编译、汇编和链接四个关键阶段。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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 '\n'(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\n");

}

 

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值