rep stos dword ptr es:[edi]

來源:互聯網
上載者:User
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

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.