News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Check if a reg have this numbers...

Started by shekel, June 24, 2015, 12:13:06 PM

Previous topic - Next topic

shekel

In AL i have a number between 0x01 and 0x0F inclusives .. so i want check if this number is 02, 03, 06, 07, 0A, 0B, 0E, 0F...

I know that all this number have something in comun and others not.

the bit in bold is always 1

2 = 00000010
3 = 00000011

How can check that this bit is 1??

Sorry by my english.. is not my native language


dedndave

test al,2
will set or clear the ZERO flag according to the value
you may then use JZ or JNZ to branch

or

bt eax,1
will set the CARRY flag if bit 1 is set
you may then use JC or JNC to branch
or, shift the CF into a register, perhaps

dedndave

those tests will tell you whether or not bit 1 is set
but, that's not the same for all values from 01h to 0Fh
01 0001
02 0010
03 0011
04 0100
05 0101
06 0110
07 0111
08 1000
09 1001
0A 1010
0B 1011
0C 1100
0D 1101
0E 1110
0F 1111


this code will work...
    or      al,al
    jz      not_1_to_F

    test    al,0F0h
    jz      not_1_to_F
is_1_to_F:


there are other ways to do it, too
if you want really fast, a look-up table might work

Gunther

Quote from: dedndave on June 24, 2015, 02:09:13 PM
if you want really fast, a look-up table might work

Yes that's the way to go. Another option could be an OR bitmask.

Gunther
You have to know the facts before you can distort them.

shekel

now this is my code...

ror al, 4               ; because i have 60 and not 06
and al,0010b                 ;
jnz section_executable  ; jump if is xx1x


Is that good?

nidud

#5
deleted

Corso

Hi,

if you only want to check any single bit (or half byte) then you can also do this.Sometimes I need it too to read any PE Chars out.
mov eax,0x11111111 ; something in eax
pushad
mov dl,al
and dl,0F0 ; bitwise
shr dl, 4 ; right shift
cmp dl, 1
je @ONE
popad
@NOT_ONE:
nop
@ONE:
    popad
    nop

Just a quick example.

greetz