flat assembler
Message board for the users of flat assembler.

Index > Main > checking registers for binary bit

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 00:31
how do i check the bx for the second binary bit, and check if it is 1 and not zero for example

say bx contains: 01111011010101011 (16 bit register)

any help?

_________________
Oh that divide overflow. Just jumps out of the bushes every time to scare the day lights out of me.
Post 12 Apr 2010, 00:31
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 00:39
Code:
test bx,0000000000000010b
jnz bit_is_set    


Last edited by bitshifter on 12 Apr 2010, 00:54; edited 2 times in total
Post 12 Apr 2010, 00:39
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 00:41
thanks a bunch
Post 12 Apr 2010, 00:41
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 00:46
well hold on

test bx, 00000000000000010 would check for
0 >>1 << 111011010101011 int he 16 digits?
Post 12 Apr 2010, 00:46
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 00:49
Code:
and bx,0000000000000010b
jnz bit_is_set    

Is the same but trashes bx
Where test preserves bx

EDIT: fixed to 16 bits instead of 17
(copy and paste burns me again)


Last edited by bitshifter on 12 Apr 2010, 00:54; edited 1 time in total
Post 12 Apr 2010, 00:49
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 00:54
my wonder is how does that check for the second digit in 01111011010101011 to see if its a 1 or 0?

oh i see its suppose to be opposite
Post 12 Apr 2010, 00:54
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 00:56
http://en.wikipedia.org/wiki/Binary_and

0000000000000010b is our mask
Post 12 Apr 2010, 00:56
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 01:07
so if i wanted to check the 3rd bit id do this

test bx, 0000000000000100b ?
Post 12 Apr 2010, 01:07
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 01:10
yep

jnz bit_is_set
jz bit_not_set
Post 12 Apr 2010, 01:10
View user's profile Send private message Reply with quote
GhostXoPCorp



Joined: 13 Dec 2008
Posts: 199
Location: 01F0:0100
GhostXoPCorp 12 Apr 2010, 01:11
thanks alot
Post 12 Apr 2010, 01:11
View user's profile Send private message Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 01:15
You can also use this trick to test sign bit of integer/decimal
values to easily check if it is < 0 else if >= 0
Post 12 Apr 2010, 01:15
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20289
Location: In your JS exploiting you and your system
revolution 12 Apr 2010, 01:22
Also:
Code:
bt bx,1
jc bit_is_set
jnc bit_is_clear    
Post 12 Apr 2010, 01:22
View user's profile Send private message Visit poster's website Reply with quote
bitshifter



Joined: 04 Dec 2007
Posts: 796
Location: Massachusetts, USA
bitshifter 12 Apr 2010, 01:28
Thanks revolution.
Its always nice to see alternate methods.
Post 12 Apr 2010, 01:28
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 13 Apr 2010, 06:35
Is there any way to compliment a single bit without changing the flags reg(no btc)?
Post 13 Apr 2010, 06:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20289
Location: In your JS exploiting you and your system
revolution 13 Apr 2010, 06:42
Tyler wrote:
Is there any way to compliment a single bit without changing the flags reg(no btc)?
Yes:
Code:
pushfd
btc bx,1
popfd    
Post 13 Apr 2010, 06:42
View user's profile Send private message Visit poster's website Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 13 Apr 2010, 06:59
Yeah, i guess your right, didn't think of that. Embarassed Smile
Post 13 Apr 2010, 06:59
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 13 Apr 2010, 07:41
lahf is better than pushf/popf.
you dont have to save high flags, only basic ones responsible for arithmetics.

and remember that in long mode you cant use conditional jumps, only movcc to accomplish it.
Post 13 Apr 2010, 07:41
View user's profile Send private message Reply with quote
Tyler



Joined: 19 Nov 2009
Posts: 1216
Location: NC, USA
Tyler 13 Apr 2010, 08:10
Quote:

and remember that in long mode you cant use conditional jumps

Really?! Do you mean you can't use conditional jumps at all in long mode?
Post 13 Apr 2010, 08:10
View user's profile Send private message Reply with quote
a115433



Joined: 05 Mar 2010
Posts: 144
a115433 13 Apr 2010, 09:09
Quote:
Do you mean you can't use conditional jumps at all in long mode?

instruction exist, and they work exactly as in 32bit mode. but you cant jump more than 2GB, and because ia32e has maximum 64bit addressing, this jump is useless, and even impossible in dynamic allocated memory. in 32 bit mode it cover exactly 4 gigs, so its ok, in ia32e mode, you have to use jmp. something like that:



test rcx,rcx
mov rax,is_zero
movnz rax,not_zero ;will replace rax only if zf is not set
jmp rax
Post 13 Apr 2010, 09:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20289
Location: In your JS exploiting you and your system
revolution 13 Apr 2010, 09:15
Tyler: a115433 has a bee in his bonnet about how Long Mode can't support jumps further than 2GB. Of course LM supports all conditional and unconditional jumps, just not all the way to 64-bit.

OMG a 64-bit IP register and only 31-bit jumps!!!!!!!
Post 13 Apr 2010, 09:15
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.