How to do inputs in x86 assembly on windows?

So I've been trying to do something like the input() from python in x86 assembly. It is like, when you run the compiled executable in the console, it prints a prompt (for eg 'give some input: ') and waits till you write something in the console and press enter, then it stores what you typed into a variable or something... I tried many ways but they don't work. Pls suggest.

My current code:

    mov     ebp, esp
    sub     esp, 4

    push    -11
    call    _GetStdHandle@4
    mov     ebx, eax    

    push    0
    lea     eax, [ebp-4]
    push    eax
    push    (prompt_len - prompt)
    push    prompt
    push    ebx
    call    _WriteFile@20
    lea eax, [format]
    push eax
    lea eax, [x_str]
    push eax
    ; Call scanf
    call _scanf
    push 0
    call _ExitProcess@4

it prints the prompt but then exits quickly, what should I do. prompt is the prompt. format db "%d",0. and x_str is the variable i want to store the input in.



  • You have the arguments for scanf the wrong way round, the format string is the first argument, the one nearest the stack pointer on entry to the function.