【译】x86程序员手册05 - 2.3寄存器

2.3 Registers 寄存器

The 80386 contains a total of sixteen registers that are of interest to the applications programmer. As Figure 2-5 shows, these registers may be grouped into these basic categories:

80386包含对应用程序有用的寄存器16个。正如图2-5所示的那样,这些寄存器可以被分成以下几类:

  1. General registers. These eight 32-bit general-purpose registers are used primarily to contain operands for arithmetic and logical operations.

通用寄存器。共有8个32位通用寄存器,主要用来数学和逻辑运算操作。

  1. Segment registers. These special-purpose registers permit systems software designers to choose either a flat or segmented model of memory organization. These six registers determine, at any given time, which segments of memory are currently addressable.

段寄存器。这些特殊的寄存器允许操作系统的设计者选择一个扁平或分段的内存组织模式。在任何时候,这6个寄存器都用来决定哪个内存段是当前可编址的。

  1. Status and instruction registers. These special-purpose registers are used to record and alter certain aspects of the 80386 processor state.

状态寄存器和指令寄存器。这些寄存器用来记录和更改80386的处理器的状态。

 

2.3.1 General Registers 通用寄存器

The general registers of the 80386 are the 32-bit registers EAX, EBX, ECX, EDX, EBP, ESP, ESI, and EDI. These registers are used interchangeably to contain the operands of logical and arithmetic operations. They may also be used interchangeably for operands of address computations (except that ESP cannot be used as an index operand).

80386的通用寄存器是32位的,包括EAX,EBX,ECX,EDX,EBP,ESP,ESI和EDI。这些寄存器用来包含逻辑和数学运算操作的操作符。它们也被用来做地址计算(除了ESP不能被用来做为索引操作)。

As Figure 2-5 shows, the low-order word of each of these eight registers has a separate name and can be treated as a unit. This feature is useful for handling 16-bit data items and for compatibility with the 8086 and 80286 processors. The word registers are named AX, BX, CX, DX, BP, SP, SI, and DI.

正如图2-5所示,这8个寄存器的低位字可以单独命名做为一个单元使用。这个特性对于处理16位的数据是很用的,也用来兼容8086和80286的处理器。字寄存器被命名为AX,BX,CX,DX,BP,SP,SI和DI。

Figure 2-5 also illustrates that each byte of the 16-bit registers AX, BX, CX, and DX has a separate name and can be treated as a unit. This feature is useful for handling characters and other 8-bit data items. The byte registers are named AH, BH, CH, and DH (high bytes); and AL, BL, CL, and DL (low bytes).

2-5也解释了16位的寄存器AX,BX,CX和DX也可以被独立命名作为一个单元使用。这个特性对于处理字符和8位数据很有用。字节寄存器被命名为AH,BH,CH和DH(高位);以及AL,BL,CL和DL(低位)。

All of the general-purpose registers are available for addressing calculations and for the results of most arithmetic and logical calculations; however, a few functions are dedicated to certain registers. By implicitly choosing registers for these functions, the 80386 architecture can encode instructions more compactly. The instructions that use specific registers include: double-precision multiply and divide, I/O, string instructions, translate, loop, variable shift and rotate, and stack operations.

所有的通用寄存器都可以用来进行地址运算,也可以用来表示大多数的数学和逻辑运算结果。然而,少量的功能被指定使用特定寄存器。在这些功能中,通过隐式地选择寄存器,80386架构能够编码复杂的指令。这些使用特定的寄存器:双精度乘除指令,I/O指令,字符指令,转换指令,循环指令,移位和翻转指令,以及栈操作。

2.3.2 Segment Registers 段寄存器

The segment registers of the 80386 give systems software designers the flexibility to choose among various models of memory organization. Implementation of memory models is the subject of Part II -- Systems Programming. Designers may choose a model in which applications programs do not need to modify segment registers, in which case applications programmers may skip this section.

80386的段寄存器让操作系统的设计者面对多模块的内存组织有更多选择。实现内存模块是第二部分的主题 —— 系统编程。设计者应当选择一种模式,使应用程序不需要修改段寄存器,应用程序设计者可以跳过这部分。

Complete programs generally consist of many different modules, each consisting of instructions and data. However, at any given time during program execution, only a small subset of a program's modules are actually in use. The 80386 architecture takes advantage of this by providing mechanisms to support direct access to the instructions and data of the current module's environment, with access to additional segments on demand.

一个完整的程序通常包含很多模块,每个模块都包含指令和数据。然而,在任何给定的程序执行时间内,只有一个程序模块的子集被真正使用。利用这种特性,80386提供一种机制支持直接访问当前模块环境中的指令和数据,需要的时候再去访问其他段。

At any given instant, six segments of memory may be immediately accessible to an executing 80386 program. The segment registers CS, DS, SS, ES, FS, and GS are used to identify these six current segments. Each of these registers specifies a particular kind of segment, as characterized by the associated mnemonics ("code," "data," or "stack") shown in Figure 2-6 . Each register uniquely determines one particular segment, from among the segments that make up the program, that is to be immediately accessible at highest speed.

在任何时刻,6个内存段随时都可以执行80386程序。段寄存器CS,DS,SS,ES,FS和GS用来标识这6个当前段。每个寄存器标识一个特定类型的段,正如图2-6中所示的相关的命名(“code”, “data”或者 “stack”)。每个寄存器唯一决定一个特定构成程序的段,它们都能立即被高速访问。

 

The segment containing the currently executing sequence of instructions is known as the current code segment; it is specified by means of the CS register. The 80386 fetches all instructions from this code segment, using as an offset the contents of the instruction pointer. CS is changed implicitly as the result of intersegment control-transfer instructions (for example, CALL and JMP), interrupts, and exceptions.

包含当前执行指令序列的段被作为当前代码段;它由CS寄存器指定。80386从代码段中取所有的指令作为指令指针的偏移量。CS寄存器的内容隐式地被节间转换指令(例如:CALL和JMP),中断和异常修改。

Subroutine calls, parameters, and procedure activation records usually require that a region of memory be allocated for a stack. All stack operations use the SS register to locate the stack. Unlike CS, the SS register can be loaded explicitly, thereby permitting programmers to define stacks dynamically.

子程序调用,参数传递和进程激活记录通常都需要为栈预先分配好一定的内存。所有的栈操作都使用SS寄存器来标记栈。不象CS那样,SS寄存器可以显示地装载,这样允许程序来动态定义栈空间。

The DS, ES, FS, and GS registers allow the specification of four data segments, each addressable by the currently executing program. Accessibility to four separate data areas helps programs efficiently access different types of data structures; for example, one data segment register can point to the data structures of the current module, another to the exported data of a higher-level module, another to a dynamically created data structure, and another to data shared with another task. An operand within a data segment is addressed by specifying its offset either directly in an instruction or indirectly via general registers.

DS,ES,FS和GS寄存器允许为当前可编址的执行程序指定4个数据段。四个独立的可数据区域有助于程序高效地同类型的数据结构;例如,一个数据段寄存器指向当前数据结构,第二个指向更高版本模块中的输出数据,第三个指向动态的数据结构,第四个指向另一个任务的共享数据。数据段间操作的寻址可以是通过指令中的偏移量直接寻址或使用通用寄存器来间接寻址。

Depending on the structure of data (e.g., the way data is parceled into one or more segments), a program may require access to more than four data segments. To access additional segments, the DS, ES, FS, and GS registers can be changed under program control during the course of a program's execution. This simply requires that the program execute an instruction to load the appropriate segment register prior to executing instructions that access the data.

通过数据结构(如:数据被分别存储在一个或多个段中),程序可以要求访问多于四个的数据段。为了访问更多的段,DS,ES,FS和GS寄存器在程序执行期间可以被程序修改。因此,执行程序装载相关的段寄存器的指令必须先于访问数据的指令。

The processor associates a base address with each segment selected by a segment register. To address an element within a segment, a 32-bit offset is added to the segment's base address. Once a segment is selected (by loading the segment selector into a segment register), a data manipulation instruction only needs to specify the offset. Simple rules define which segment register is used to form an address when only an offset is specified.

和每个段的段寄存器的基址与处理器相关联。要寻址一个段内元素,32位的地址偏移要被加到段的基址上。一旦一个段被处理器选择(通过装载段选择子到一个段寄存器),数据操作指令仅需要指定一个偏移地址即可。这样就形成一个简单的规则:仅当一个偏移地址被指定时,段寄存器才能被用来构成一个地址。

2.3.3 Stack Implementation 栈实现

Stack operations are facilitated by three registers:

栈操作和三个寄存器相关:

  1. The stack segment (SS) register. Stacks are implemented in memory. A system may have a number of stacks that is limited only by the maximum number of segments. A stack may be up to 4 gigabytes long, the maximum length of a segment. One stack is directly addressable at a -- one located by SS. This is the current stack, often referred to simply as "the" stack. SS is used automatically by the processor for all stack operations.

栈段寄存器(SS)。栈是一段内存。系统可以有多个栈,这只受限于段的最大数量。栈最大可以为4G,也就是一个段的最大长度。通过SS栈可以直接寻址。通常使用the来标识当前栈。处理器对所有栈操作都自动使用SS寄存器。

  1. The stack pointer (ESP) register. ESP points to the top of the push-down stack (TOS). It is referenced implicitly by PUSH and POP operations, subroutine calls and returns, and interrupt operations. When an item is pushed onto the stack (see Figure 2-7 ), the processor decrements ESP, then writes the item at the new TOS. When an item is popped off the stack, the processor copies it from TOS, then increments ESP. In other words, the stack grows down in memory toward lesser addresses.

栈指针寄存器。ESP指向栈顶(TOS = push-down stack)。ESP可以被PUSH和POP操作、子程序调用和返回语句以及中断操作隐式修改。当一个项入栈(见图2-7),处理器减少ESP值,然后将该项写入新的栈顶(TOS)。当一个项被弹出栈,处理器从栈顶拷贝(TOS)这个元素,然后增加ESP值。换名话说,栈在内存中向下增长(从高地底端向低地址商)。

  1. The stack-frame base pointer (EBP) register. The EBP is the best choice of register for accessing data structures, variables and dynamically allocated work space within the stack. EBP is often used to access elements on the stack relative to a fixed point on the stack rather than relative to the current TOS. It typically identifies the base address of the current stack frame established for the current procedure. When EBP is used as the base register in an offset calculation, the offset is calculated automatically in the current stack segment (i.e., the segment currently selected by SS). Because SS does not have to be explicitly specified, instruction encoding in such cases is more efficient. EBP can also be used to index into segments addressable via other segment registers.

栈帧基址指针寄存器。EBP寄存器在访问数据结构、变量和栈内动态分配的工作空间而言是最好的选择。EBP寄存器经学用来访问栈上元素,这些元素与变化的栈指针相关而不是与当前栈顶(TOS)相关。它能区别建立在当前程序上的账帧基址。在偏移量计算中EBP被用作基址寄存器,偏移量可在在当前栈段中自动计算(一般而言当前栈段是由SS选择的)。在这种情况下,SS不用明确指定,所在指令编码更加高效。通过其他段寄存器,EBP也可以用来做段中地址的索引。

 

2.3.4 Flags Register 标志寄存器

The flags register is a 32-bit register named EFLAGS. Figure 2-8 defines the bits within this register. The flags control certain operations and indicate the status of the 80386.

标志寄存器也叫EFLAGS,是32位寄存器。图2-8展示了这个寄存器中各位的意义和作用。这些标志控制一定的操作或表明80386处理器的状态。

The low-order 16 bits of EFLAGS is named FLAGS and can be treated as a unit. This feature is useful when executing 8086 and 80286 code, because this part of EFLAGS is identical to the FLAGS register of the 8086 and the 80286.

EFLAGS的低16位也叫FLAGS,可以被视作一个单元。这个特性在执行8086和80286代码时很有用,因为这部分对应8086和80286的FLAGS寄存器。

The flags may be considered in three groups: the status flags, the control flags, and the systems flags. Discussion of the systems flags is delayed until Part II.

标志可以分成三组:状态标志,控制标志,系统标志。直到第二部分才会讨论系统标志。

 

2.3.4.1 Status Flags 状态标志

The status flags of the EFLAGS register allow the results of one instruction to influence later instructions. The arithmetic instructions use OF, SF, ZF, AF, PF, and CF. The SCAS (Scan String), CMPS (Compare String), and LOOP instructions use ZF to signal that their operations are complete. There are instructions to set, clear, and complement CF before execution of an arithmetic instruction. Refer to Appendix C for definition of each status flag.

EFLAGS的状态标志允许一条指令的结果影响下一条指令。数据指令使用OF(溢出),SF(信号标志),ZE(0标志),AF(辅助进位标志),PF(奇偶标志)和CF(进位标志)。SCAS指令(扫描字符串),CMPS(比较字符串)和LOOP(循环)指令使用ZF来指示这些操作是否完成。有些指令在执行算数指令前会设置、清除和补充CF。参考附录C关于每个状态标志的定义。

2.3.4.2 Control Flag 控制标志

The control flag DF of the EFLAGS register controls string instructions. DF (Direction Flag, bit 10) Setting DF causes string instructions to auto-decrement; that is, to process strings from high addresses to low addresses. Clearing DF causes string instructions to auto-increment, or to process strings from low addresses to high addresses.

EFLAGS的控制标志DF控制字符串指令。DF(方向标志,位10),DF置位会导致字符串指令自动递减;因此字符串处理会从高地址到低地址。清除DF会导致字符串指令自动递增,换言之处理字符串从低地址到高地址。

2.3.4.3 Instruction Pointer 指令指针寄存器

The instruction pointer register (EIP) contains the offset address, relative to the start of the current code segment, of the next sequential instruction to be executed. The instruction pointer is not directly visible to the programmer; it is controlled implicitly by control-transfer instructions, interrupts, and exceptions.

EIP包含基于当前代码段的地址偏移量,下一个指令会被执行。指令指针寄存器对于程序而言不能直接可见;它隐式地由控制转换指令、中断或异常来进行控制修改。

As Figure 2-9 shows, the low-order 16 bits of EIP is named IP and can be used by the processor as a unit. This feature is useful when executing instructions designed for the 8086 and 80286 processors.

正如图2-9所示,EIP的低16位被命名为IP,可以被处理器当做一个单元使用。当执行为8086和80286设计的指令时这个特性很有用。

 

 

转载于:https://www.cnblogs.com/mqmelon/p/6692140.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值