flat assembler
Message board for the users of flat assembler.

Index > Main > Fast Bitset in block of data

Author
Thread Post new topic Reply to topic
omegicus



Joined: 16 Jul 2013
Posts: 8
Location: Ukraine
omegicus
Hi everybody!

Have a problem, may be someone can help me with:

I have, for example, index 300 and i need to set (!)bit #300 in datablock...

Is any algorithm to do this more beautiful than using dividing to find needed dword in data...

Thanks!
Post 26 Mar 2015, 19:48
View user's profile Send private message Reply with quote
omegicus



Joined: 16 Jul 2013
Posts: 8
Location: Ukraine
omegicus
My draft version is (in my code i need to CLEAR bit in 0xFFFFFFF-filled array, not set);

Code:
align 4
clearBit: ; esi: data, ecx: index of byte
        pushad
        mov       eax, ecx
        ;
        shr       eax, 3        ; /8
        add       esi, eax
        shl       eax, 3        ; *8
        sub       ecx, eax
        ;
        mov       eax, 0xFFFFFF7F
        dec       ecx                      ; needed in my code only
        shr       eax, cl
        and       byte[esi], al
        ;
        popad
ret     



also set bit should be:
Code:
align 4
setBit: ; esi: data, ecx: index of byte
        pushad
        mov       eax, ecx
        ;
        shr       eax, 3        ; /8
        add       esi, eax
        shl       eax, 3        ; *8
        sub       ecx, eax
        ;
        mov      eax, 0xFFFFFF80
        dec       ecx                   ; needed in my code only
        shr       eax, cl
        or        byte[esi], al
        ;
        popad
ret     


This functions sets bits in linear-style, left-to-right, not in x86 specific low-order bitwise... so setting insex 0 will produce 1000000... real data...



With Revolution code:
Code:
align 4
clearBit_RevolutionMod: ; esi: data, ecx: index of byte
        pushad
        mov       eax, ecx
        ;
        shr       eax, 3        ; /8
        add       esi, eax
        shl       eax, 3        ; *8
        sub       ecx, eax
        ;
        xor        ecx, 7
        bts        byte[esi],ecx
        ;
        popad
ret     


Last edited by omegicus on 27 Mar 2015, 07:51; edited 3 times in total
Post 26 Mar 2015, 21:21
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17714
Location: In your JS exploiting you and your system
revolution
What about this?
Code:
xor ecx,7
bts byte[esi],ecx    
Post 26 Mar 2015, 23:26
View user's profile Send private message Visit poster's website Reply with quote
omegicus



Joined: 16 Jul 2013
Posts: 8
Location: Ukraine
omegicus
puted modified code in 1'st post
Post 26 Mar 2015, 23:34
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.