0

I am new to assembly and I am struggling to use scanf in assembly using at&t syntax. I researched a lot and everything that I found looked like there has to be an easier solution.

I got printf to work like this:

.data
output1: .asciz "Hello World!\n"

.text
.global main
main:
    movq $output1, %rdi
    xorq %rax, %rax
    call printf

Now I simply want to the same thing using scanf and storing the user input in a register. Something like this:

.data
output1: .asciz "Enter your number: "
format: .asciz "%d"

.text
.global main
main:
    movq $output1, %rdi
    xorq %rax, %rax
    call printf

    // this is just pseudo code, I am aware that this does not work
    movq $format, %rdi
    xorq %rax, %rax
    call scanf

How would I do this using scanf? Please note that I am new to assembly and this might be an easy question for some of you. However, I researched a lot and couldn't find anything like that.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Tom el Safadi
  • 6,164
  • 5
  • 49
  • 102

0 Answers0