I’m trying to figure out how to use scanf to get user input. I know to use printf: all I have to do is push the data I want to write on the screen into the stack like this:
global _main
extern _printf
extern _scanf
section .data
msg db "Hi", 0
section .text
_main:
push ebp
mov ebp, esp
push msg
call _printf
mov esp, ebp
pop ebp
ret
But I can’t figure out how to use scanf. Can someone please just give me the simplest possible source code you can for scanf? I really just want to put what the user types in.
I’m not used to 32bit Assembly. I’ve only ever used 16bit, and I know in 16bit (DOS) you can just do this:
mov ah, 3fh
mov dx, input
int 21h
input rb 100d
And whatever you type in will the placed at the address of “input.”
I found this ‘Programming in NASM.PDF’
Which is the asm version of this C function: