我参加了计算机体系结构课程,我了解到处理器有 32 个 32 位寄存器。现在我正在学习计算机体系结构课程,其中我读到 8086 只有8 个寄存器。但是我读的书和这个网站显示了很多寄存器。我对 8086 和 8088 中的寄存器感到困惑。请帮帮我。
笔记:
我对不同处理器中的不同寄存器大小有很好的理解。我只是对寄存器的数量感到困惑。
8086 和 8088 是 16 位处理器 - 它们的寄存器均为 16 位宽度。(一些指令将 DX 和 AX 的组合视为 32 位整数,如 div 输入和 mul 输出。)
注意8086有16位数据总线;8088 有一个 8 位数据总线。(因此加载/存储 16 位字需要 2 个总线周期。两者的地址仍然是 20 位。)
通用寄存器
8086 CPU有8个通用寄存器,每个寄存器都有自己的名字:
AX——累加器寄存器(分为AH/AL):
Generates shortest machine code: short-form encodings exist
Arithmetic, logic and data transfer
One number must be in AL or AX
Multiplication & Division
Input & Output
BX——基址寄存器(分为BH/BL)。
Offset address relative to DS by default
CX——计数寄存器(分为CH/CL):
The LOOP instruction uses it implicitly as a counter
Repetitive operations on strings with the REP command
Count (in CL) of bits to shift and rotate
DX——数据寄存器(分为DH/DL):
DX:AX concatenated into 32-bit register for some MUL and DIV operations
Specifying ports in some IN and OUT operations
SI - 源索引寄存器:
Can be used for pointer addressing of data
Used as source in some string processing instructions
Offset address relative to DS by default
DI - 目标索引寄存器:
Can be used for pointer addressing of data
Used as destination in some string processing instructions as ES:DI
Offset address relative to DS outside of string instructions
BP - 基指针:
Primarily used to access parameters and locals on the stack
Offset address relative to SS
SP - 堆栈指针:
Always points to top item on the stack
Offset address relative to SS (but can't be used in 16-bit addressing modes)
Should always points to word (byte at even address)
An empty stack will have SP = FFFEh
段寄存器
尽管可以在段寄存器中存储任何数据,但这绝不是一个好主意。段寄存器有一个非常特殊的用途——指向可访问的内存块。
段寄存器与通用寄存器一起工作以访问任何内存值。例如,如果我们想访问物理地址 12345h(十六进制)的内存,我们可以设置 DS = 1230h 和 SI = 0045h。这样我们就可以形成 20 位的线性地址,而不是只有 16 位的单个寄存器。(这适用于实模式;在保护模式中分段是不同的。)
CPU 通过将段寄存器乘以 10h 并将通用寄存器加到其中来计算物理地址(1230h * 10h + 45h = 12345h):
由 2 个寄存器组成的地址称为有效地址。
默认情况下,BX、SI 和 DI 寄存器与 DS 段寄存器一起使用;
BP 和 SP 与 SS 段寄存器一起工作。
其他通用寄存器不能形成有效地址。
另外,虽然 BX 可以形成有效地址,但 BH 和 BL 不能。
特殊用途寄存器
IP——指令指针:
Always points to next instruction to be executed
Offset address relative to CS
IP 寄存器总是与 CS 段寄存器一起工作,它指向当前正在执行的指令。
标志寄存器
标志寄存器 - 确定处理器的当前状态。它们在数学运算后由 CPU 自动修改,这允许确定结果的类型,并确定将控制权转移到程序其他部分的条件。通常您不能直接访问这些寄存器。
Carry Flag (CF) - this flag is set to 1 when there is an unsigned overflow. For example when you add bytes 255 + 1 (result is not in range 0...255). When there is no overflow this flag is set to 0.
Parity Flag (PF) - this flag is set to 1 when there is even number of one bits in (the low 8 bits of a) result, and to 0 when there is odd number of one bits.
Auxiliary Flag (AF) - set to 1 when there is an unsigned overflow (carry-out) for low nibble (4 bits).
Zero Flag (ZF) - set to 1 when result is zero. For non-zero result this flag is set to 0.
Sign Flag (SF) - set to 1 when result is negative. When result is positive it is set to 0. (This flag takes the value of the most significant bit.)
Trap Flag (TF) - Used for on-chip debugging.
Interrupt enable Flag (IF) - when this flag is set to 1 CPU reacts to interrupts from external devices.
Direction Flag (DF) - this flag is used by some instructions to process arrays. When this flag is set to 0 the processing is done forward, when this flag is set to 1 the processing is done backward.
Overflow Flag (OF) - set to 1 when there is a signed overflow. For example, when you add bytes 100 + 50 (result is not in range -128...127).
8086 有 14 个 16 位寄存器。AX、BX、CX、DX、SI、DI、BP、SP、CS、DS、SS、ES、IP 和标志寄存器。最后两个只能间接访问。
我参加了计算机体系结构课程,我了解到处理器有 32 个 32 位寄存器。
这并不能回答您的问题,但如果您想与另一位工程师交流,您必须使用正确的语言。说“一个(某些)处理器有 32 个大小为 32 位的寄存器”不会让你到任何地方,处理器数量不计其数。
8086 有八个(或多或少通用)16 位寄存器,包括堆栈指针,但不包括指令指针、标志寄存器和段寄存器。其中四个,AX,BX,CX,DX,也可以访问两倍的 8 位寄存器(见图),而其他四个,BP,SI,DI,SP,只有 16 位。
我假设混淆来自维基百科上的这句话。您阅读的两个来源都是正确的。有 8 个通用寄存器(在文章中它被称为“或多或少通用”,我不知道谁会写),它们是:AX BX CX DX 和 SI DI BP SP。还有段寄存器,特殊用途寄存器和标志寄存器(在“排除”字之后注明,我猜,应该被读作“有寄存器,如果你排除这些,则有8个3组”,含糊不清)。
问题在于措辞。引用的句子令人困惑,我可以看到您的问题来自哪里。提问永远不会有坏处,但您应该明白,维基百科不是可靠的知识来源,如果您感到困惑,只需拿起一本书。
计算机体系结构书籍经常使用 MIPS 作为示例,因为它相当简单且具有教育意义。MIPS 有 32 个寄存器,但这并不意味着其他 32 位架构也有 32 个寄存器。这里的32-bit仅表示计算机有32 位地址/32 位整数寄存器。它与寄存器的数量没有任何关系。
ARM 是最流行的 32 位架构,有 16 个寄存器(尽管 ARMv8 64 位使这个数字翻了一番,达到 32 个)。许多其他 32 位架构也有 32 个以外的寄存器编号,例如 Motoroka 68k 和 SuperH v2/3/4,它们都有 16 个寄存器。架构列表请看这里。你看,64 位架构很少有 64 个寄存器,因为这会大大增加寄存器文件的大小,并使上下文切换变得更糟。他们中的大多数有 32 个寄存器。
x86 与几十年前的 8086 向后兼容,只有 8 个可见整数寄存器。但实际上现在的 x86 CPU 内部有数百个寄存器,并使用寄存器重命名来克服寄存器数量的限制。