Here is the code:
.data
format_in: .string "%ld"
format_out: .string "Number of 1s in the given number %ld = %ld\n"
.text
.globl main
main:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
leaq -8(%rbp), %rsi
leaq format_in(%rip), %rdi
movq $0, %rax
call scanf
movq -8(%rbp), %rdi
call rcount1s
movq %rax, -16(%rbp)
movq -8(%rbp), %rsi
movq -16(%rbp), %rdx
leaq format_out(%rip), %rdi
movq $0, %rax
call printf
leave
ret
rcount1s:
pushq %rbp
movq %rsp, %rbp
subq $16, %rsp
cmpq $0, %rdi
jne .L2
movq $0, %rax
jmp .L3
.L2:
movq %rdi, -8(%rbp)
andq $1, -8(%rbp)
sarq $1, %rdi
call rcount1s
addq -8(%rbp), %rax
.L3:
leave
ret
when i execute it using:
$ as -gstabs task.s -o task.o
$ ld -dynamic-linker /lib64/ld-linux-x86-64.so.2 -e main task.o -o task -lc
$ ./task
It prints segmentation fault.
i've tried to link to scanf library many times, but unsuccessfully`