I played with assembly on my PC. I wrote following program which ouputs a string first via the write syscall of Linux and second via a call to printf
.text
.global main
main:
# write syscall
movl $4, %eax
movl $1, %ebx
movl $message, %ecx
movl $len, %edx
int $0x80
#push %rax
# printf
push %rbp
mov %rsp,%rbp
mov $message, %rdi
callq printf
pop %rbp
#pop %rax
movl $0x0, %eax
retq
.data
message: .ascii "Hello World, I'm an assembly program\n\0"
len = . - message - 1
The program works fine. But as soon as I uncomment the two push/pop %rax commands the program throws a segmentation fault inside the printf routine. The push/pop has no sense in this case but i wonder why it destroys the printf.
Why does this happen?
Thank you