首页 > 其他 > 详细

关于寄存器的一些笔记

时间:2018-12-26 19:12:42      阅读:150      评论:0      收藏:0      [点我收藏+]

 

有次面试时,面试官问我,当一个进程(注意是活动进程而不是程序)hang住时,怎么知道它卡在哪里了?它当时在做什么?当时,我脑子一片糊涂,完全不知道这个问题要怎么回答,甚至包括面试官问我为什么linux命令行上一组用管道连接起来的多个命令直接能够接受输出和进行输出,每个命令的代码开发时事先并不知道有管道这回事,这个问题都没有回答上来。后来静下心来回想这个问题时,一个进程在执行时一定有上下文,有堆栈,那么查看它的堆栈和上下文应该就能知道它在做什么了。不过即使我这么回答,面试官估计还会追问我具体使用什么工具去查看,我还是回答不了,因为我对这些底层的东西只有一点点了解,大概也就知道APUE和操作系统中介绍的那些“概念”了,调试程序只是依赖日志,对底层并没有深刻的体验,也没有具体的认识。出于对底层的兴趣,也出于技术需要不断学习的认知,决定重拾汇编语言,顺便刷一刷《深入理解计算机系统》。

上面都是废话,下面记一下最近学习汇编语言时个人的一个好奇点,汇编当中少不了和寄存器打交道,寄存器命名在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.

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,好有意思。

不过,A、B、C、D寄存器的名字真的是按字母这么选择的吗?就像数学里面公式,选择x和y并没有什么特别的含义?事实上,A、B、C、D寄存器的名字是一种缩写,全称是:

A: accumulator A寄存器通常是函数返回值的存放处。

B: base

C: count C寄存器通常是for循环中计数存放处

D: data

关于寄存器的一些笔记

原文:https://www.cnblogs.com/pluse/p/10180728.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!