x86 Registers

来源:互联网 发布:卡尔曼滤波 知乎 编辑:程序博客网 时间:2024/05/21 21:42

x86 Registers


The main tools to write programs in x86 assembly are the processor registers. The registers are like variables built in the processor. Using registers instead of memory to store values makes the process faster and cleaner. The problem with the x86 serie of processors is that there are few registers to use. This section describes the main use of each register and ways to use them. That in note that the rules described here are more suggestions than strict rules. Some operationsneed absolutely some kind of registers but most of the you can use any of the freely.

Here is a list of the available registers on the 386 and higher processors.This list shows the 32 bit registers. Most of the can be broken down to 16 or even 8 bitsregister.
General registersEAX EBX ECX EDXSegment registersCS DS ES FS GS SSIndex and pointersESI EDI EBP EIP ESPIndicatorEFLAGS
General registers
As the title says, general register are the one we use most of the timeMost of the instructions perform on these registers. They all can be broken downinto 16 and 8 bit registers.
32 bits :  EAX EBX ECX EDX16 bits : AX BX CX DX 8 bits : AH AL BH BL CH CL DH DL
The "H" and "L" suffix on the 8 bit registers stand for high byte and low byte.With this out of the way, let's see their individual main use
EAX,AX,AH,AL : Called the Accumulator register.                It is used for I/O port access, arithmetic, interrupt calls,               etc...EBX,BX,BH,BL : Called the Base register               It is used as a base pointer for memory access               Gets some interrupt return valuesECX,CX,CH,CL : Called the Counter register               It is used as a loop counter and for shifts               Gets some interrupt valuesEDX,DX,DH,DL : Called the Data register               It is used for I/O port access, arithmetic, some interrupt                calls.
Segment registers

Segment registers hold the segment address of various items. They are only availablein 16 values. They can only be set by a general register or special instructions.Some of them are critical for the good execution of the program and you mightwant to consider playing with them when you'll be ready for multi-segment programming
CS         : Holds the Code segment in which your program runs.             Changing its value might make the computer hang.DS         : Holds the Data segment that your program accesses.             Changing its value might give erronous data.ES,FS,GS   : These are extra segment registers available for             far pointer addressing like video memory and such.SS         : Holds the Stack segment your program uses.             Sometimes has the same value as DS.             Changing its value can give unpredictable results,             mostly data related.
Indexes and pointers

Indexes and pointer and the offset part of and address. They have various usesbut each register has a specific function. They some time used with a segment registerto point to far address (in a 1Mb range). The register with an "E" prefix can onlybe used in protected mode.
ES:EDI EDI DI : Destination index register                Used for string, memory array copying and setting and                for far pointer addressing with ESDS:ESI EDI SI : Source index register                Used for string and memory array copyingSS:EBP EBP BP : Stack Base pointer register                Holds the base address of the stack                SS:ESP ESP SP : Stack pointer register                Holds the top address of the stackCS:EIP EIP IP : Index Pointer                Holds the offset of the next instruction                It can only be read 
The EFLAGS register

The EFLAGS register hold the state of the processor. It is modified by many intructionsand is used for comparing some parameters, conditional loops and conditionnal jumps.Each bit holds the state of specific parameter of the last instruction. Here is a listing :
Bit   Label    Desciption---------------------------0      CF      Carry flag2      PF      Parity flag4      AF      Auxiliary carry flag6      ZF      Zero flag7      SF      Sign flag8      TF      Trap flag9      IF      Interrupt enable flag10     DF      Direction flag11     OF      Overflow flag12-13  IOPL    I/O Priviledge level14     NT      Nested task flag16     RF      Resume flag17     VM      Virtual 8086 mode flag18     AC      Alignment check flag (486+)19     VIF     Virutal interrupt flag20     VIP     Virtual interrupt pending flag21     ID      ID flagThose that are not listed are reserved by Intel.
Undocumented registers

There are registers on the 80386 and higher processors that are not well documentedby Intel. These are divided in control registers, debug registers, test registers andprotected mode segmentation registers. As far as I know, the control registers, alongwith the segmentation registers, are used in protected mode programming, all of these registersare available on 80386 and higher processors except the test registers that have been removedon the pentium. Control registers are CR0 to CR4, Debug registers are DR0 to DR7, testregisters are TR3 to TR7 and the protected mode segmentation registers are GDTR (Global DescriptorTable Register), IDTR (Interrupt Descriptor Table Register), LDTR (Local DTR), and TR.


ref[1]: http://www.eecg.toronto.edu/~amza/www.mindsec.com/files/x86regs.html

0 0
原创粉丝点击