Nov 10, 2017 09:22 AM
(This post was last modified: Nov 10, 2017 09:28 AM by theChive.)
Anyone have any suggestions for toggling (EDIT (clarifying): switch from a 1 to a 0 or vice versa) a given bit within a number in 64 bit x86 assembly?
Something like:
I'm not quite sure how to manipulate the number. I figured I could do a loop and jump when I am sitting on the specified bit, but I'm thinking there is an easier way to do this that I'm unaware of.
Any and all suggestions are greatly appreciated!
Something like:
Code
toggle:
mov rax, 0x0 # zero rax
mov rax, rdi # move first argument (the number whose bit will be toggled) to rax
mov rbx, 0x0 # zero rbx
mov rbx, rsi # move second argument (the bit number within the first argument to be toggled) to rbx
# toggle the bit?
ret # return the value after having the specified bit toggled (which is sitting in rax)I'm not quite sure how to manipulate the number. I figured I could do a loop and jump when I am sitting on the specified bit, but I'm thinking there is an easier way to do this that I'm unaware of.
Any and all suggestions are greatly appreciated!
Keep calm, chive on.


