In my assembly program I want to test that standard input reached its EOF
segment .data
.fmt_read db "%80s", 0 ; 79 bytes of actual string + terminating 0
segment .text
lea rdi, [.fmt_read]
lea rsi, [buf_str] ; buffer to fill in
xor eax, eax ; no floating-point parameters are passed
call scanf
cmp rax, -1 ; did we reach EOF(-1)
je .done ; yes? End the program
When I debug it in gdb I press Ctrl-D to make the scanf recognise EOF. Then test return value in rax, hoping to find an EOF indicator(-1).
(gdb) p $rax
$5 = 4294967295
(gdb) p/x $rax
$6 = 0xffffffff
I understand that it is the value -1 in binary two's complement.
Although, I did not understand why cmp rax, -1
did not set ZF(as they are equal).
How to determine EOF?