Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You do not need to find the length of the string after the call to <code>wsprintf</code> as it returns the number of characters copied to the buffer.</p> <p>Next, there is what is called <a href="http://en.wikipedia.org/wiki/Application_binary_interface" rel="nofollow">Application binary interface (ABI)</a> which covers many details such as <a href="http://en.wikipedia.org/wiki/X86_calling_conventions" rel="nofollow">Calling Conventions</a></p> <p>When you are dealing with the Windows API, or C runtimes, they follow these calling conventions, where <code>esi</code>, <code>edi</code>, <code>ebx</code>, <code>ebp</code>, and <code>esp</code> are saved across the function call. Which means, if you have a value in one of those registers, then call an API function, that value will still be the same after the call.</p> <p><code>eax</code>, <code>ecx</code>, and <code>edx</code> do not have to be saved, so anything you have in those registers before a call is NOT guaranteed to be the same. if you have something in those registers, and you need that value after a call, you need to save to a variable or the stack with <code>push</code></p> <p><code>eax</code> is used for return values.</p> <p>That being said, in this sample, I use <code>ebx</code> as the loop counter, and <code>esi</code> as the current number to print, as those values will stay the same across API calls.</p> <p>This is NASM, but it will give you and idea.</p> <pre><code>%include "externs.inc" %define STD_OUTPUT_HANDLE -11 %define STD_INPUT_HANDLE - 10 %define NULL 0 SECTION .data strFormat DB "Number %d ",13,10,0 SECTION .bss buf resb 16 stdout resd 1 stdin resd 1 lpNumRead resd 1 inChar resb 1 global start2 SECTION .text start2: push STD_OUTPUT_HANDLE call GetStdHandle mov [stdout], eax push STD_INPUT_HANDLE call GetStdHandle mov [stdin], eax mov ebx, 10000 mov esi, 1 CountOut: push esi push strFormat push buf call wsprintf add esp, 4 * 3 push NULL push lpNumRead push eax push buf push dword [stdout] call WriteConsole inc esi dec ebx jnz CountOut push NULL push lpNumRead push 1 push inChar push dword [stdin] call ReadConsole push 0 call ExitProcess </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.
    1. This table or related slice is empty.
    1. VO
      singulars
      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