If you've just used an instruction that modifies ZF before, simply check that flag and jump using `JZ` or `JE`. For example
and rax, rbx ; ZF was modified
jz is_zero ; so to check if rax is zero, a single jump is enough
If ZF was not set, you need to do that explicitly. The obvious way is
cmp rax, 0
je equal_zero
However since `cmp` is longer if you look at the output binary, [`test`](
[To see links please register here]
) or sometimes [`and`, `or`](
[To see links please register here]
) is preferred
83F800 cmp eax, 0
09C0 or eax, eax
85C0 test eax, eax
The resulting code will be
test rax, rax
jz is_zero
You can get the assembly output from a compiler and check or view it in an online tool like [gcc godbolt][1]
Read more:
[To see links please register here]
[1]:
[To see links please register here]
:'//+Type+your+code+here,+or+load+an+example.%0Aint+is_zero(int+x,+int+*y,+int+*z)+%7B%0A+++if+(x+%3D%3D+0)%0A+++++*y+%3D+*z%3B%0A+++else%0A+++++*y+%3D+-*z%3B%0A%7D%0A'),l:'5',n:'0',o:'C%2B%2B+source+%231',t:'0')),k:25.650950254211345,l:'4',n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:g71,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O2',source:1),l:'5',n:'0',o:'x86-64+gcc+7.1+(Editor+%231,+Compiler+%231)',t:'0')),k:35.5645638630054,l:'4',m:100,n:'0',o:'',s:0,t:'0'),(g:!((h:compiler,i:(compiler:icc17,filters:(b:'0',commentOnly:'0',directives:'0',intel:'0'),options:'-O2',source:1),l:'5',n:'0',o:'x86-64+icc+17+(Editor+%231,+Compiler+%232)',t:'0')),k:38.78448588278327,l:'4',m:100,n:'0',o:'',s:0,t:'0')),l:'2',n:'0',o:'',t:'0')),version:4