Rep STOs dword ptr es: [EDI]

Source: Internet
Author: 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]

I cannot understand the role of the highlighted statement. I found the answer in a post on 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]

That is, the purpose of the rep command is to repeat the preceding command. The value of ECx is the number of repetitions.

So, the code I listed is used to assign 0 xcccccccc to the memory of the stack starting from the ebp-0xcc and repeat 0x33 (51) times. note that 0xcccccccc indicates that it is not initialized.

 

To clarify the functions of STOs and rep, the above answer is not hard to understand.

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

The role of the STOs command is to copy the values in eax to ES: address pointed to by EDIIf Direction Flag is set, EDI will decrease after the command is executed. If Direction Flag is not set, the value of EDI will increase to prepare for the next storage.

Rep can be the prefix of any character passing command (CMPS, lods, movs, SCAs, STOs.Rep can trigger the subsequent string commands to be repeated. As long as the ECX value is not 0, the repetition will continue. After each string command is executed, the ECX value will be reduced.

 

References

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

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.