"rep stos"是什么? x86汇编指令序列如何? [英] What does the "rep stos" x86 assembly instruction sequence do?
问题描述
我最近偶然发现了以下汇编指令序列:
I recently stumbled across the following assembly instruction sequence:
rep stos dword ptr [edi]
推荐答案
对于ecx
重复,将eax
的内容存储到edi
指向,递增或递减edi
的位置(取决于方向标记) )每次4字节.通常,这用于memset
型操作.
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.
通常,该指令只是写为rep stosd
.经验丰富的汇编编码人员一看就知道上面提到的所有细节. :-)
Usually, that instruction is simply written rep stosd
. Experienced assembly coders know all the details mentioned above just by seeing that. :-)
ETA的完整性(感谢PhiS):每一次迭代,ecx
都会减1,并且当循环达到零时,循环会停止.对于stos
,您将观察到的唯一情况是最后清除了ecx
.但是,对于使用repz
/repnz
前缀的scas
等,如果操作在耗尽ecx
字节/字/任何内容之前已停止,则ecx
可以大于零.
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.
在询问之前,scas
用于实现strchr
类型的操作. :-P
Before you ask, scas
is used for implementing strchr
-type operations. :-P
这篇关于"rep stos"是什么? x86汇编指令序列如何?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!