Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You call GetStdHandle and save the returned value to ecx, ecx is a volatile register, the value will not be saved across calls unless you push/pop it. Your first call to WriteConsoleA uses it and clobbers it so the next call, ecx is not what you expect.</p> <p><strong>* EDIT *</strong> I was bored so here is working code:</p> <pre><code>[bits 32] section .data program db "Program: ", 0 programlen equ $-program nl db "", 13, 10, 0 nllen equ $-nl section .bss buf resd 1 argc resd 1 argv resb 255 section .text global Start extern GetStdHandle extern __getmainargs extern WriteConsoleA extern ExitProcess strlen: ; eax: a string ending in 0 push eax ; cache eax .strloop: mov bl, byte [eax] cmp bl, 0 je .strret ; return len if bl == 0 inc eax ; else eax++ jmp .strloop .strret: pop ebx ; ebx = cached eax sub eax, ebx ; eax -= ebx ret ; eax = len Start: push 0 push buf push argv push argc call __getmainargs add esp, 16 ; clear stack (4 * 4 arguments) push -11 ; get stdout call GetStdHandle mov esi, eax add esp, 4 ; clear stack (4 * 1 argument) push 0 ; null push buf ; [chars written] push programlen push program push esi ; stdout call WriteConsoleA add esp, 20 ; clear stack (4 * 5 arguments) mov edx, [argv] mov eax, [edx] ; &lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; call strlen push 0 ; null push buf ; [chars written] push eax ; len argv[0] push dword [edx] ;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt;&lt; ; argv[0] push esi ; stdout call WriteConsoleA add esp, 20 ; clear stack (4 * 5 arguments) push 0 ; null push buf ; [chars written] push nllen push nl push esi ; stdout call WriteConsoleA add esp, 20 ; clear stack (4 * 5 arguments) push 0 call ExitProcess D:\NASM Projects\ReadArgs&gt;ReadArgs.exe Program: ReadArgs.exe D:\NASM Projects\ReadArgs&gt; </code></pre>
 

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