In other words, is there any case I might need this instruction?
From Intel Instructions Manual, this is what the instruction do:
Load (E)CX bytes from DS:[(E)SI] to AL.
Take the following example in NASM:
section .data
src: db 0, 1, 2, 3
section .code
mov esi, src
mov ecx, 4
rep lodsb ; mov al, byte[esi + ecx -1]; ecx++
While the instruction rep lodsb
is executing, I don't have any control over the value loaded in al
. All I can do is waiting, until the instruction terminates to get the last value of al
, which, of course I can get directly, without the loop.
The same question goes for the rest of the family: REP LODS AX
, REP LODS EAX
and REP LODS RAX
.
LODS
is the only one in that family of instructions which does not take a repeat prefix. – RenaldorenardlodsX
has side effects: it changesr/e/di
and the direction of the loop is determined by theDF
flag. Furthermore, it can trigger an exception and will (inefficiently) cache the data (if caching is enabled). – Drawshaver/e/si
. – Drawshaveal
too, but we can't do anything, besides watching it changing. – Alarickrep lods
easily. – BluejacketLODS
clearly says: "TheLODS
,LODSB
,LODSW
, andLODSD
instructions can be preceded by theREP
prefix for block loads ofECX
bytes, words, or doublewords. More often, however, these instructions are used within aLOOP
construct because further processing of the data moved into the register is usually necessary before the next transfer can be made." So either the manual means thatREP
prefixes are rarely useful, or it meansREPE
/REPNE
prefixes (that testZF
) can't be used withLODS
. – DowdellLODS
is given as None. Further on in the discussion ofLODS
it says Unlike other string instructions,LODS
is not normally used with a repeat prefix. So it was a careless paraphrase, mybad, I missed out the word "usually". – Renaldorenardrep lods
, on the assumption that nobody would ever use it on purpose (since you could always code it withdb
or whatever). Apparently that's not the case, but both the Intel and MASM docs could have been correct in saying what you claimed. – Buschi