So while I was trying to program something in assembly, I stumbled upon a problem. I'm trying to scan in two variables, using the scanf subroutine, and then printing them both in one sentence, using the printf subroutine. Now this seemed to work on a virtualbox instance(linux) that I'm using, but since I was not sattisfied with the input lag I had with virtualbox, I installed ubuntu 16.04 alongside my original OS, which is windows 10.
So I was all happy with the way my Linux was working, without any input lag. Then I tried to compile and run the same code as in the virtualbox (which worked there!) and for some reason got a "Segmentation fault (core dumped)" error.
If I do the scanf subroutine once and print the input, it works fine. But when I use the scanf subroutine twice, it just stops working after entering 1 value in the terminal.
Can somebody please tell me what's wrong, or what might be wrong/different by using Ubuntu instead of the virtualbox?
Example of my code (comments won't properly stay aligned):
.text
scanner: .asciz "%ld" #format string for scanning
output: .asciz "%ld%ld\n" #format string for second printing
.global main
main:
movq %rsp, %rbp #initialize basepointer
call thing #call inout subroutine
jmp end #jump to end
thing:
pushq %rbp #basepointer value to stack
movq %rsp, %rbp #basepointer set to stackpointer
subq $8, %rsp #move rsp up by 8
leaq -8(%rbp), %rsi #allocate memory input
movq $scanner, %rdi #put scanner in rdi
movq $0, %rax #no vector register in use for scanf
call scanf #call scanf routine
subq $8, %rsp #move rsp up by 8
leaq -16(%rbp), %rsi #allocate memory input (under previous one)
movq $scanner, %rdi #put scanner in rdi
movq $0, %rax #no vector register in use for scanf
call scanf #call scanf routine
movq $output, %rdi #put output in rdi
movq -8(%rbp), %rsi #set input value in rsi
movq -16(%rbp), %rdx #set second input value in rdx
movq $0, %rax #no vector register in use for printf
call printf #call the printf routine
movq %rbp, %rsp #clean the stack
popq %rbp #reset basepointer
ret #return to main
end:
movq $0, %rdi #load program exit code
call exit #exit the program
Thanks in advance!