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 '\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.
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 开发者必知的日志记录最佳实践
· SQL Server 2025 AI相关能力初探
· Linux系列:如何用 C#调用 C方法造成内存泄露
· AI与.NET技术实操系列(二):开始使用ML.NET
· 记一次.NET内存居高不下排查解决与启示
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· 没有Manus邀请码?试试免邀请码的MGX或者开源的OpenManus吧
· 园子的第一款AI主题卫衣上架——"HELLO! HOW CAN I ASSIST YOU TODAY
· 【自荐】一款简洁、开源的在线白板工具 Drawnix