I think I'm missing an important concept when it comes to the assembly stack. I wanted to push the value of the register rcx, since the called function uses this register, but I get a seg fault. I know that if I put push rbx before push rcx (for pop after) the code works. Is there a good reason behind this (to me it seems pointless) ?
.intel_syntax noprefix
.data
wrtfrmt: .asciz "%c\n"
rdfrmt: .asciz "%d"
.bss
.lcomm val, 4
.text
.global main
main:
enter 0,0
lea rdi, rdfrmt
lea rsi, val
call scanf
mov ebx, val
lea rdi, rdfrmt
lea esi, val
call scanf
mov ecx, val
next:
push rcx
lea rdi, rdfrmt
lea esi, val
call scanf
pop rcx
cmp ebx, val
loopne next
jne not_found
mov esi, 'y'
jmp print
not_found:
mov esi, 'y'
print:
lea rdi, wrtfrmt
call printf
leave
ret