I have a simple program here that is supposed to take two integers from the user and add them together. However, for some reason, I am getting an insanely huge result every time. I was wondering if someone could explain why that is happening.
.file "addition.s"
.section .rodata
message1:
.string "Please enter an integer on the next line:\n"
SC_1:
.string "%li"
message2:
.string "Please enter a second integer on the next line:\n"
SC_2:
.string "%li"
message3:
.string "Your integer + %ld = %ld\n"
.data
x:
.quad 0
y:
.quad 0
.globl main
.type main, @function
.text
main:
pushq %rbp
movq %rsp, %rbp
movq $message1, %rdi
movq $0, %rax
call printf
movq $x, %rsi
call scanf
movq $message2, %rdi
movq $0, %rax
call printf
movq $y, %rsi
movq $SC_2, %rdi
movq $0, %rax
call scanf
addq %rsi, x #I also tried addq $y, x which did not work (why?)
movq x, %rsi
movq $message3, %rdi
movq $0, %rax
call printf
movq $0, %rax
leave
ret
.size main, .-main""
This program is code I copied from a program that originally took an integer form the user then added 5 to it. Because of that, there are some things I don't understand about it which I will mention if anyone could possibly provide an explanation:
What is SC_1 and SC_2 doing (I added the second one since I figured it had to do with taking input)/ What is the function of the string "%li"? I guess wrapped up in that question I am also trying to understand how the compiler knows where to store the value scanned in from scanf? Why do I have to have .size main, .-main at the end and what does it do?
disclaimer : I have to use this syntax (and the gcc) because I am learning this in a class in university and this program is me trying to practice and understand how all this works (my teacher is really not very helpful unfortunately)