Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 693 Vote(s) - 3.45 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to check if a register is zero in x86_64 assembly

#1
I'm trying to check if a value is zero in x86_64 assembly code. I know that this usually consist of a `cmp` variant followed by a `jmp` variant, but I'm not sure of the exact instructions to use.
Reply

#2
test %eax, %eax ; set ZF to 1 if eax == 0
je 0x804f430 ; jump to 0x00804f4 if ZF == 1

`ZF` is a single bit zero flag which will be set to 1 if `eax` be equal to zero. `je` will take the jump to `0x804f430` if the `ZF` be set to 1.
Reply

#3
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
Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through