ILD

x86寄存器
作者:Herbert Yuan 邮箱:yuanjp89@163.com
发布时间:2017-6-29 站点:Inside Linux Development

参考

http://www.hep.wisc.edu/~pinghc/x86AssmTutorial.htm

寄存器总览

EAX,EBX,ECX,EDX 

- "general purpose", more or less interchangeable

EBP    

- used to access data on stack

- when this register is used to specify an address, SS is used implicitly

ESI,EDI   

- index registers, relative to DS,ES respectively


SS,DS,CS,ES,FS,GS    

- segment registers

- (when Intel went from the 286 to the 386, they figured that providing more segment registers would be more useful to programmers than providing more general-purpose registers... now, they have an essentially RISC processor with only _FOUR_ GPRs!)

- these are all only 16 bits in size

EIP     

- program counter (instruction pointer), relative to CS


ESP   

- stack pointer, relative to SS


EFLAGS     

- condition codes, a.k.a. flags

段寄存器

i486 addresses are formed from a segment base address plus an offset. To compute an absolute memory address, the i486 figures out which segment register is being used, and uses the value in that segment register as an index into the global descriptor table (GDT). The entry in the GDT tells (among other things) what the absolute address of the start of the segment is. The processor takes this base address and adds on the offset to come up with the final absolute address for an operation. 


i486 has 6 16-bit segment registers, listed here in order of importance:

  1. CS: Code Segment Register
    Added to address during instruction fetch.

  2. SS: Stack Segment Register
    Added to address during stack access.

  3. DS: Data Segment Register
    Added to address when accessing a memory operand that is not on the stack.

  4. ES, FS, GS: Extra Segment Registers
    Can be used as extra segment registers; also used in special instructions that span segments (like string copies).

The x86 architecture supports different addressing modes for the operands. A discussion of all modes is out of the scope of this tutorial, and you may refer to your favorite x86 reference manual for a painfully-detailed discussion of them. Segment registers are special, you can't do a

    movw seg-reg, seg-reg

You can, however, do

    movw seg-reg,memory
    movw memory,seg-reg
    movw seg-reg,reg
    movw reg,seg-reg

Note: If you movw %ss,%ax, then you should xorl %eax,%eax first to clear the high-order 16 bits of %eax, so you can work with long values.

Copyright © linuxdev.cc 2017-2024. Some Rights Reserved.