I have encountered a problem with printf spitting out segfaults whenever there is only one element in the stack. Here, what I want the script to do is print 5, only then do the add operation, but segmentation fault happens.
Interestingly, if I push 6 right after I push 5 and then print, it works. Thus, I suppose the problem occurs when there is only one element in the stack.
Any ideas?
Thank you in advance!
.fmt:
.asciz "%d\n"
.text
.globl _start
_start:
push $5
pop %rdx
mov %rdx, %rsi
push %rdx
mov $.fmt, %rdi
call printf
xor %rax, %rax
push $6
pop %rdx
pop %rcx
add %rdx, %rcx
push %rcx
mov $60, %rax
pop %rdi
syscall