tags:

views:

117

answers:

2
rep stos    dword ptr [edi]
+2  A: 

For ecx repetitions, stores the contents of eax into where edi points to, incrementing or decrementing edi (depending on the direction flag) by 4 bytes each time. Normally, this is used for a memset-type operation.

Usually, that instruction is simply written rep stosd. Experienced assembly coders know all the details mentioned above just by seeing that. :-)


ETA for completeness (thanks PhiS): Each iteration, ecx is decremented by 1, and the loop stops when it reaches zero. For stos, the only thing you will observe is that ecx is cleared at the end. But, for scas or the like, where the repz/repnz prefixes are used, ecx can be greater than zero if the operation stopped before exhausting ecx bytes/words/whatevers.

Before you ask, scas is used for implementing strchr-type operations. :-P

Chris Jester-Young
Can you give an example what it does?
COMer
@COMer - It's already in the anwser: like memset - it fills a specified (ecx) amount of memory (at [edi]) with a given value (in eax).
PhiS
@Chris Jester-Young - for completeness' sake, I'd suggest you mention that it will also decrement ecx by one each iteration until ecx reaches 0.
PhiS
How to know whether it's ecx or other kinds of repetitions ?
COMer
@COMer: It always uses register 1 (`cx`/`ecx`/`rcx`). In your case, since you're using the 32-bit instruction, it will use the 32-bit version of that register, thus, `ecx`.
Chris Jester-Young
@PhiS: I added something, though I don't know if it's comprehensive enough. :-P
Chris Jester-Young
A: 

It's part of the C function __cdecl prologue on Windows (which is probably where you got it from) and it fills E/CX dwords at ES:[E/DI] with AL/AX/EAX.

David Titarenco
No, that's wrong. It stores `ecx` _dwords_ (in the OP's case), not bytes.
Chris Jester-Young
Thanks! Fixed, need to brush up on my ASM :]
David Titarenco