有次面试时,面试官问我,当一个进程(注意是活动进程而不是程序)hang住时,怎么知道它卡在哪里了?它当时在作什么?当时,我脑子一片糊涂,彻底不知道这个问题要怎么回答,甚至包括面试官问我为何linux命令行上一组用管道链接起来的多个命令可以直接串联起来进行输入输出,每一个命令的代码开发时事先并不知道有管道这回事,这个问题都没有回答上来。后来静下心来回想这个问题时,一个进程在执行时必定有上下文,有堆栈,那么查看它的堆栈和上下文应该就能知道它在作什么了。不过即便我这么回答,面试官估计还会追问我具体使用什么工具去查看、如何查看,我仍是回答不了,由于我对这些底层的东西只有一点点了解,大概也就知道APUE和操做系统中介绍的那些“理论概念”了,平时调试程序只是依赖日志,对底层并无深入的体验,也没有具体的认识。出于对底层的兴趣,也出于技术须要不断学习的认知,决定重拾汇编语言,顺便刷一刷《深刻理解计算机系统》。linux
上面都是废话,下面记一下最近学习汇编语言时我的的一个好奇点,汇编当中少不了和寄存器打交道,寄存器命名在16位是ax,32位是eax,64位是rax,那么8位CPU时代,8位的寄存器名称是怎么样的?面试
虽然16位CPU向后兼容8位CPU,16位寄存器能够分为2个8位寄存器,分别叫作ah和al,但很显然ah、al确定不是8位CPU时代寄存器的名字,由于ah、al是16位时代的命名,而8位比16位出现的要早。最后在stackoverflow中找到其命名,内容以下:函数
The register names have evolved over the past 40 years. The Intel 8080 processor, introdced in 1974, had 8 bit registers named A, B, C, D, E, H and L. A thru E seem fairly obvious but H and L? Well, they were combined into the 16 bit HL register which was primarily used as a memory pointer, so H for high and L for low.工具
In 1979 Intel released the 8086 processor (the original IBM PC was based on its close cousin the 8088). The 8086 had 16 bit registers 4 "main" ones and 4 index registers. The main registers were called AX, BX,CX, DX a natural eXtension of the 8080's A thru D, each of these could also be referenced as 8 bit registers which were called AL, AH, BL, BH, etc. The 8086 index register, also 16 bit, were called SI, DI, BP and SP after their primary functions. SI and DI for Sorce and Destination Index, SP for Stack Pointer, and BP for (stack) Base Pointer.学习
The extension to the 32 bit world, with the introdction of the 80386 in 1986, brought us EAX, EBX, ECX, EDX, ESI, EDI, EBP and ESP, the 32 bit variants of the registers, the 80386 names remained for the (lower) 16 bits and the 8 bit accessing required to mainain comaptibility.ui
There things stood until AMD, beating Intel to market, defined 64-bit extensions.操作系统
It is perhaps interesting to note that binary code assembled for the 8086 processor is compatible with all the X86 processors which succeeded it.命令行
References:调试
http://everything2.com/title/CPU+history%253A+A+timeline+of+microprocessors http://en.wikipedia.org/wiki/Intel_8080 http://en.wikipedia.org/wiki/Intel_8086 http://en.wikipedia.org/wiki/Intel_80386
从上面的回答能够看到,寄存器名字的历史涉及40多年的演化,计算机中不少东西都与历史缘由有关。寄存器也是,8位的寄存器名称居然就是A、B、C、D,好有意思。rest
不过,A、B、C、D寄存器的名字真的是按字母这么选择的吗?就像数学里面公式,选择x和y并无什么特别的含义?事实上,A、B、C、D寄存器的名字是一种缩写,全称是:
A: accumulator A寄存器一般是函数返回值的存放处。
B: base
C: count C寄存器一般是for循环中计数存放处
D: data
当寄存器从8位进化到16位时,命名从A变成了AX,X是什么意思?下面来自stackoverflow的回答解答了这个问题:
The X means pair, and goes back to at least the 8080. It had 8-bit registers B,C,D,E,H,L (among others) which could also be used in pairs (BC, DE and HL). The BC and DE pairs were used mostly for 16-bit arithmetic; the HL pair generally held a memory address.
X的意思是一对,这个意思比较显然,由于16位的AX能够拆分为2个8位寄存器:AH和AL。
当寄存器从16位进化到32位时,命名从AA变成了EAX,E是什么意思?这个相关的说明比较容易找到,E表示 "extended" 或 "enhanced",即扩展或者加强的意思。
最后,64位寄存器RAX中的R是什么意思?网上说就是register寄存器的意思,但这个说法很明显不像前面那样贴切合理。