Through some manipulation I have narrowed it down to a problem with the ret
op. I know call
pushes the return address to the stack; is it illegal to pop it and push it back?
format ELF64 executable 3
entry start
segment readable executable
start:
pop rcx ; argc
mov [argc],cl ; int -> ASCII
add [argc],'0'
push 1 argc 1
call sys_write
mov rdi,0
mov rax,60
syscall
sys_write: ; (fd,*buf,count)
pop r11
pop rdx rsi rdi
mov rax,1
syscall
push r11
ret
segment readable writable
argc rb 1
Output is:
$ ./prog
1Segmentation fault
$ _