|
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. 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
operations need absolutely some kind of registers but most of the
you can use any of the freely. General registers EAX EBX ECX EDX Segment registers CS DS ES FS GS SS Index and pointers ESI EDI EBP EIP ESP Indicator EFLAGS
General
registers 64 bits : RAX RBX RCX RDX
32 bits : EAX EBX ECX EDX
16 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 RAX,EAX,AX,AH,AL : Called the Accumulator register. It is used for I/O port access, arithmetic, interrupt calls, etc... RBX,EBX,BX,BH,BL : Called the Base register It is used as a base pointer for memory access Gets some interrupt return values RCX,ECX,CX,CH,CL : Called the Counter register It is used as a loop counter and for shifts Gets some interrupt values RDX,EDX,DX,DH,DL : Called the Data register It is used for I/O port access, arithmetic, some interrupt calls.
Segment
registers 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 ES:RDI EDI EDI DI : Destination index register Used for string, memory array copying and setting andfor far pointer addressing with ES DS:RSI ESI EDI SI : Source index register Used for string and memory array copying SS:RBP EBP EBP BP : Stack Base pointer register Holds the base address of the stack SS:RSP ESP ESP SP : Stack pointer register Holds the top address of the stack CS:RIP IP EIP IP : Index Pointer Holds the offset of the next instruction It can only be read
The
EFLAGS register Bit Label Desciption --------------------------- 0 CF Carry flag 2 PF Parity flag 4 AF Auxiliary carry flag 6 ZF Zero flag 7 SF Sign flag 8 TF Trap flag 9 IF Interrupt enable flag 10 DF Direction flag 11 OF Overflow flag 12-13 IOPL I/O Priviledge level 14 NT Nested task flag 16 RF Resume flag 17 VM Virtual 8086 mode flag 18 AC Alignment check flag (486+) 19 VIF Virutal interrupt flag 20 VIP Virtual interrupt pending flag 21 ID ID flag
x86 64-bit General Purpose Registers There are 16 (+1) registers in 64-bit x86: RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, R8 through R15 and RIP. RAX: The accumulator. This register typically stores return values from functions. RBX: This register is typically the pointer to the base of an array. RCX: This is typically used as a counter: loops, iterating through an array etc. RDX: Commonly used as a supporting register. For example, 64 bit return values are returned in EDX:EAX in the code generated by 32 bit compilers. RSI: The source index for string operations. RDI: The destination index for string operations. RBP: This register points to the base of the current function’s stack frame. RSP: This register points to the top of the current function’s stack frame. R8: R9: R10: R11: R12: R13: R14: R15: RIP: This register, the Program Control Register, points to the address of the next instruction. This is the only instruction that cannot be manipulated by any instruction except call and return
x86 64-bit Register Conventions Caller save registers: These registers have to be saved by the caller function if it wants to preserve their values. RAX, RCX and RDX are caller save registers. RAX is usually modified by the callee in almost all cases(it holds the return value remember?) Callee save register: These registers have to be saved by callee function if it will modify these registers. RBP, RBX, RDI and RSI are callee save registers. RBP is usually modified by the callee in almost all cases(it points to the base of the function’s stack frame remember?) |
|
|
Return to Professor Page]