I made a program in x64 assembly, using AT&T syntax, but I don't figure out why mov operator copies address variable to register. Here is my code:
.globl main
.text
main:
mov $a, %rax
mov $format, %rdi # set 1st parameter (format)
mov %rax, %rsi # set 2nd parameter (current_number)
mov $0, %rax # because printf is varargs
sub $8, %rsp # align stack pointer
call printf # printf(format, sum/count)
add $8, %rsp # restore stack pointer
ret
.data
a: .quad 123
format: .asciz "%d\n"
The program outputs 6295616 instead of 123. Please help me understand what I've done wrong.
Because you have indicated with the dollar sign that you want immediate mode. Remove it to get absolute mode.