get string input in windows x64 assembly

Viewed 25
bits 64
default rel

segment .data
    grs db "name: "
    inpt db "%s"

segment .text
    global main


extern printf
extern scanf
extern _CRT_INIT
extern ExitProcess

global main
    
exit:
    xor rax, rax
    call ExitProcess

main:
    push rbp
    mov rbp,rsp
    sub rsp, 32

    lea rcx, [grs]
    mov rax, rcx
    call printf ;printing the grs variable

    lea rcx, [inpt];the problem starts here

    
    jmp exit

i am very new to assembly, I push %s into scanf so I type something on the console (like hello world) and press enter. Logically, the text I wrote needs to be saved somewhere, but I couldn't find how to do it.

I use these two commands to build

  1. nasm -f win64 -o "main.obj" "main.asm"

  2. link "C:\Users\xx\Desktop\assembly_x64\get_input\main.obj" /subsystem:console /entry:main /defaultlib:ucrt.lib /defaultlib:msvcrt.lib /defaultlib:legacy_stdio_definitions.lib /defaultlib:Kernel32.lib /nologo /incremental:no /opt:ref /out:"main.exe"

0 Answers
Related