rep stos dword ptr es:[edi]

0:000> uf .
monitor!main [c:\users\myalias\documents\visual studio 2005\projects\mytest\mytest\main.c @ 32]:
   32 0042f780 55              push    ebp
   32 0042f781 8bec            mov     ebp,esp
   32 0042f783 81eccc000000    sub     esp,0CCh
   32 0042f789 53              push    ebx
   32 0042f78a 56              push    esi
   32 0042f78b 57              push    edi
   32 0042f78c 8dbd34ffffff    lea     edi,[ebp-0CCh]
   32 0042f792 b933000000      mov     ecx,33h
   32 0042f797 b8cccccccc      mov     eax,0CCCCCCCCh
   32 0042f79c f3ab            rep stos dword ptr es:[edi]

有点不明白高亮语句的作用, 在stackoverflow的一篇帖子中找到了答案.

; This puts the address of the stack frame bottom (lowest address) into edi...
         lea     edi,[ebp-0C0h]
; ...and then fill the stack frame with the uninitialised data value (ecx = number of 
; dwords, eax = value to store)
        mov     ecx,30h
        mov     eax,0CCCCCCCCh
        rep stos dword ptr es:[edi]

即, rep指令的目的是重复其上面的指令. ECX的值是重复的次数.

所以, 我列出的代码的作用是将栈上从ebp-0xcc开始的位置向高地址方向的内存赋值0xCCCCCCCC,次数重复0x33(51)次. 注意0xCCCCCCCC代表着未被初始化.

 

把STOS和REP的功能弄清楚, 上面的答案就不难理解了.

=================

STOS指令的作用是将eax中的值拷贝到ES:EDI指向的地址. 如果设置了direction flag, 那么edi会在该指令执行后减小, 如果没有设置direction flag, 那么edi的值会增加, 这是为了下一次的存储做准备.

REP可以是任何字符传指令(CMPS, LODS, MOVS, SCAS, STOS)的前缀. REP能够引发其后的字符串指令被重复, 只要ecx的值不为0, 重复就会继续. 每一次字符串指令执行后, ecx的值都会减小.

 

参考资料

===================

Can anyone help me interpret this simple disassembly from WinDbg?

http://stackoverflow.com/questions/4024492/can-anyone-help-me-interpret-this-simple-disassembly-from-windbg

STOS

http://www.cs.ubbcluj.ro/~dadi/ac/doc/ng1cf0a.html

REP

http://www.cs.ubbcluj.ro/~dadi/ac/doc/ng15a5f.html


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值