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