组装:REP MOVS 机制 [英] Assembly: REP MOVS mechanism

查看:33
本文介绍了组装:REP MOVS 机制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看下面的汇编代码:

MOV ESI, DWORD PTR [EBP + C]
MOV ECX, EDI
MOV EAX, EAX
SHR ECX, 2
LEA EDI, DWORD PTR[EBX + 18]
REP MOVS DWORD PTR ES:[EDI], DWORD PTR [ESI]
MOV ECX, EAX
AND ECX, 3
REP MOVS BYTE PTR ES:[EDI], BYTE PTR[ESI]

我得到代码摘录的那本书将第一个 REP MOVS 解释为复制 4 字节块,第二个 REP MOVS 复制剩余的 2 字节块, 如果存在.

The book I got the code excerpt from explains the first REP MOVS as copying over 4-byte chunks, with the second REP MOVS copying the remaining 2-byte chunk, if it exists.

REP MOVS 指令如何操作?根据 MSDN,该指令可以以 REP 为前缀,以重复 ecx 寄存器指定的次数."那不是一遍又一遍地重复相同的操作吗?

How do the REP MOVS instructions operate? According to MSDN, "The instruction can be prefixed by REP to repeat the operation the number of times specified by the ecx register." Wouldn't that just repeat the same operation over and over again?

推荐答案

有关特定指令的问题,请始终查阅指令集参考.

For questions about particular instructions always consult the instruction set reference.

在这种情况下,您需要查找repmovs.简而言之,rep 重复以下字符串操作ecx 次.movs 将数据从 ds:esi 复制到 es:edi 并根据设置增加或减少指针方向标志.因此,重复它会将一定范围的内存移动到其他地方.

In this case, you will need to look up rep and movs. In short, rep repeats the following string operation ecx times. movs copies data from ds:esi to es:edi and increments or decrements the pointers based on the setting of the direction flag. As such, repeating it will move a range of memory to somewhere else.

PS:通常操作大小编码为指令后缀,所以人们用movsbmovsd来表示byte双字操作.但是,某些汇编程序允许通过 byte ptrdword ptr 指定您的示例中的大小.此外,操作数隐含在指令中,您无法修改它们.

PS: usually the operation size is encoded as an instruction suffix, so people use movsb and movsd to indicate byte or dword operation. Some assemblers however allow specifying the size as in your example, by byte ptr or dword ptr. Also, the operands are implicit in the instruction, and you can not modify them.

这篇关于组装:REP MOVS 机制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆