Intel 64, rsi and rdi registers

AssemblyX86 64

Assembly Problem Overview


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?

Assembly Solutions


Solution 1 - Assembly

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 https://stackoverflow.com/questions/2535989/what-are-the-calling-conventions-for-unix-linux-system-calls-on-i386-and-x86-6)

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.)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionJonathan.View Question on Stackoverflow
Solution 1 - AssemblydelehefView Answer on Stackoverflow