flat assembler
Message board for the users of flat assembler.

Index > Main > best way of handling bits

Thread Post new topic Reply to topic

Joined: 21 May 2010
Posts: 287
b1528932 31 Jan 2011, 02:10
Some time ago i wanted to make a math library working on arbitrary lengthed data (all basic math operations for start). Now i have some time and i can finally do that. However i have some variables that i cant quite manage.

For example, is it worth doing it for bits? Function would took those arguments (addition):

a + b = c
- bytes touched by a
- bytes touched by b
- byte containing position of LSB ORed with byte containing position of MSB LSH 3
- output buffer with avaiable a + b space

is it worth handling bits that way? Are there any popular algorithms i might run into in future containing retarded positioning of bits?

For example: Data has 32 bytes, 4 bytes is a, 4 bytes is b, 12 bits is c, 7 bits is d, 3 bits is e, rest if f. Calculate f*e/a+b*r/d^e.

Will i find myself copying each unaligned ammount of bits into separate buffer instead of just using a function on it?

Is is simply worth making library (wich i want to be public and want people like using it) wich support this positioning of bits? It would take approximatly 3 times more coding, and would be much slower. Or just make requirement that each variable passed must be byte aligned?
Post 31 Jan 2011, 02:10
View user's profile Send private message Reply with quote
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 20203
Location: In your JS exploiting you and your system
revolution 31 Jan 2011, 03:44
"Best" in what way? "Best" for what purpose?

You have to define your goals before you can know what is best to meet those goals.

If your goal is to use the smallest amount of memory possible then best for that would be very different from a goal to compute answers as fast as possible.

It all depends upon what you want to achieve.
Post 31 Jan 2011, 03:44
View user's profile Send private message Visit poster's website Reply with quote

Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 10 Mar 2011, 00:27
(re)found the answer right now.
i never focused on bitfields before to do the translation of the BT instruciton (BTC, BTS, BTR are derivates)

and now, i can say that there is an instruction (a set of instrucitons) to act directlly on bits, one by one, exactlly as if they were bytes.

just look at this little test code:
        org 100h
        push 0b800h
        pop es
        mov cx,256*8-1
        mov di,0
        mov ah,4fh
        bt [bitfield],cx
        mov al,'0'
        adc al,0
        loop @b
times 256 db %-1    

and see the result:

BT wrote:


then, what is appearing?

BT op1,op2
if op1 is mémory, and op2 is register, the adress of the bit is picked from the register, the high part is used to locate the byte, and the low part used to locate the bit in the byte.

then, what is cool with this instruciton, it just needs few operands, and the bit index can be directlly taken from a zero based value.

in fact, i never saw a clear explanation of this fact before to dive more in instrucitons set. and i want to share this with you.
before, i believed BT was just used to scan a bit in a single data, and just remembered a little some lecture about the total adressing of any bit in the range of many bits.

if op2 is a 32 bit register, and op1 is memory, you can scan up to 256 MB ram with just a loop.

this instruction will be very interresting for something i planned about file system.
scan sector map to find first available disk zone.

and no matter the time it takes, my computer spend a lot of time doing nothing, and doing it bad because it is win98.
Post 10 Mar 2011, 00:27
View user's profile Send private message Visit poster's website Reply with quote

Joined: 05 Aug 2009
Posts: 570
Location: Brazil
Teehee 10 Mar 2011, 01:16
hey ed, do you think i can use that in my font issue?

also, whats does that mean: times 256 db %-1

Sorry if bad english.
Post 10 Mar 2011, 01:16
View user's profile Send private message Reply with quote

Joined: 20 Feb 2006
Posts: 4330
Location: Now
edfed 10 Mar 2011, 11:07
Post 10 Mar 2011, 11:07
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:  

< 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.