What is the actual purpose and use of the EDI & ESI registers in assembler?
I know they are used for string operations for one thing.
Can someone also give an example?
SI
= Source Index
DI
= Destination Index
As others have indicated, they have special uses with the string instructions. For real mode programming, the ES
segment register must be used with DI
and DS
with SI
as in
movsb es:di, ds:si
SI and DI can also be used as general purpose index registers. For example, the C
source code
srcp [srcidx++] = argv [j];
compiles into
8B550C mov edx,[ebp+0C]
8B0C9A mov ecx,[edx+4*ebx]
894CBDAC mov [ebp+4*edi-54],ecx
47 inc edi
where ebp+12
contains argv
, ebx
is j
, and edi
has srcidx
. Notice the third instruction uses edi
mulitplied by 4 and adds ebp
offset by 0x54 (the location of srcp
); brackets around the address indicate indirection.
AX
= accumulator
DX
= double word accumulator
CX
= counter
BX
= base register
They look like general purpose registers, but there are a number of instructions which (unexpectedly?) use one of them—but which one?—implicitly.