Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your not using <code>ebx</code> in your procedure, why save it? It does not need to be saved. <code>ecx</code> is a volatile register, you do not need to save it.</p> <p>As gnometorule, mentioned, your parameters in your proc are off.</p> <p>Another biggie is that you do not restore the stack pointer at the end. Sure you <code>pop ebp</code>, but where do you <code>mov esp, ebp</code>??? You <code>mov ebp, esp</code> at the beginning, but never reverse it.</p> <p>If you look at <code>memset</code>, it returns the pointer passed to the proc. So, this is wrong: <code>mov eax, edi</code> it should be: <code>mov eax, [ebp + 8]</code>. <code>rep stos?</code> increments the pointer in <code>edi</code> so if you return <code>edi</code>, the returned pointer is wrong.</p> <p>But why even set up a stack frame for this tiny proc? Just use <code>esp</code>, since we need to save <code>edi</code> to the stack, the params in <code>esp</code> will be offset the same as if we set up a stack frame:</p> <pre><code>kmemset: push edi ; proc uses edi, so save it. mov ecx, [esp + 16] ; size_t num mov al, [esp + 12] ; int value mov edi, [esp + 8] ; void * ptr rep stosb mov eax, [esp + 8] ; return pointer pop edi ; restore edi ret ; let caller adjust stack </code></pre> <p>using <code>stosw</code> will be a bit different.</p> <pre><code>SomeProc: push ebp mov ebp, esp push edi ; params are at: ;~ ebp + 8 ;~ ebp + 12 ;~ ebp + 16 etc... ; ... ; ... ; ... pop edi ; the following 2 lines ; can be replaced with ; leave mov esp, ebp pop ebp ret </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload