Lods byte ptr ds:[esi] ;i know that it loads a byte that is a pointer my question is " is the pointer ds with esi as an offset or is it the other way around or am i just plain wrong" ?

Edited 6 Years Ago by avarionist: n/a

esi just contains an address that is within the ds segment. ds is not a pointer -- it contains the address of the data segment. Sometimes you might even see cs:[esi] or even ss:[esi] in which case esi is pointer to somewhere in the code segment or stack segment, respectively.

esi just contains an address that is within the ds segment. ds is not a pointer -- it contains the address of the data segment. Sometimes you might even see cs:[esi] or even ss:[esi] in which case esi is pointer to somewhere in the code segment or stack segment, respectively.

thanks AncientDragon :) you have all the answers :D

The default for a [si] [esi] [rsi] access is the ds: Data segment / selector. But it can be overriden with an alternate such as AncientDragon indicated
cs: Code Segment/Selector,
es:Extra Segment/Selector,
ss: Stack Segment/Selector
fs, gs Selectors

Another item to note is LODS also increments the index by the size of the data referenced!

Assuming 32-bit Protected Mode

lodsb
   mov al,ds:[esi]
   add esi,1
lodsw
   mov ax,ds:[esi]
   add esi,2
lodsd
   mov eax,ds:[esi]
   add esi,4

You can use the Repeat instruction rep

rep lodsd
L1: mov eax,ds:[esi]
   add esi,4
   dec ecx
   jne L1

The default for a [si] [esi] [rsi] access is the ds: Data segment / selector. But it can be overriden with an alternate such as AncientDragon indicated
cs: Code Segment/Selector,
es:Extra Segment/Selector,
ss: Stack Segment/Selector
fs, gs Selectors

Another item to note is LODS also increments the index by the size of the data referenced!

Assuming 32-bit Protected Mode

lodsb
   mov al,ds:[esi]
   add esi,1
lodsw
   mov ax,ds:[esi]
   add esi,2
lodsd
   mov eax,ds:[esi]
   add esi,4

You can use the Repeat instruction rep

rep lodsd
L1: mov eax,ds:[esi]
   add esi,4
   dec ecx
   jne L1

Thanks for the info lods is an instruction i rarely see let alone use :)

This article has been dead for over six months. Start a new discussion instead.