in Intel 64 architecture there is the rax..rdx registers which are simply A..D general purpose registers.
But there are also registers called rsi and rdi which are the "source index" and "destination index" registers. why do these registers have actual names (compared to just A, etc)?
What does "source index" and "destination index" actually mean? And is there some convention that says these registers should be used in specific circumstances?
In Objective-C, the RDI register is the reference of the calling NSObject , RSI is the Selector, RDX is the first parameter and so on. In Swift, RDI is the first argument, RSI is the second parameter, and so on provided that the Swift method isn't using dynamic dispatch.
rbp - register base pointer (start of stack) rsp - register stack pointer (current location in stack, growing downwards) rsi - register source index (source for data copies) rdi - register destination index (destination for data copies)
As well, 64-bit x86 includes SSE2, so each 64-bit x86 CPU has at least 8 registers (named XMM0–XMM7) that are 128 bits wide, but only accessible through SSE instructions.
These registers were originally implicitly used in repetitive instructions, for instance MOVSB
, which copy a byte from DS:SI
(DataSegment:SourceIndex) to ES:DI
(ExtraSegment:DestinationIndex), at the time of the 16-bits computers with segmented memory in real mode. And also as index registers in 16-bit addressing modes like [bx + si]
.
Right now, these registers are for example used to transmit the first two (integer) function parameters in UNIX's x86_64 ABI, far from their original purpose. (See also What are the calling conventions for UNIX & Linux system calls on i386 and x86-64)
The names of the new rXX
64-bit registers clearly show that old register names are only here for familiarity and retro-compatibility. (But note that some instructions do still only work with some registers, for example rep movsb
only works as a memcpy(rdi, rsi, rcx)
, and is in fact why RDI and RSI were chosen as the first 2 arg-passing registers in the x86-64 System V ABI: some functions call memset
or memcpy
with their first 1 or 2 args, so inlining rep movsb/d
is cheaper in that case.)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With