The MASM Forum

General => The Campus => Topic started by: shekel on June 24, 2015, 12:13:06 PM

Title: Check if a reg have this numbers...
Post by: shekel on June 24, 2015, 12:13:06 PM
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

Title: Re: Check if a reg have this numbers...
Post by: dedndave on June 24, 2015, 12:56:21 PM
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
Title: Re: Check if a reg have this numbers...
Post by: dedndave on June 24, 2015, 02:09:13 PM
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
Title: Re: Check if a reg have this numbers...
Post by: Gunther on June 24, 2015, 10:14:05 PM
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
Title: Re: Check if a reg have this numbers...
Post by: shekel on June 25, 2015, 04:26:43 AM
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?
Title: Re: Check if a reg have this numbers...
Post by: nidud on June 25, 2015, 04:55:08 AM
deleted
Title: Re: Check if a reg have this numbers...
Post by: Corso on June 25, 2015, 07:22:05 AM
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