flat assembler
Message board for the users of flat assembler.

Index > Main > best way of handling bits

Author
Thread Post new topic Reply to topic
b1528932



Joined: 21 May 2010
Posts: 287
b1528932
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
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17474
Location: In your JS exploiting you and your system
revolution
"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
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
(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:
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
        stosw
        loop @b
        ret
bitfield:
times 256 db %-1    

and see the result:

BT wrote:

01111111111111110111111011111110011111011111110101111100111111000111101111111011
01111010111110100111100111111001011110001111100001110111111101110111011011110110
01110101111101010111010011110100011100111111001101110010111100100111000111110001
01110000111100000110111111101111011011101110111001101101111011010110110011101100
01101011111010110110101011101010011010011110100101101000111010000110011111100111
01100110111001100110010111100101011001001110010001100011111000110110001011100010
01100001111000010110000011100000010111111101111101011110110111100101110111011101
01011100110111000101101111011011010110101101101001011001110110010101100011011000
01010111110101110101011011010110010101011101010101010100110101000101001111010011
01010010110100100101000111010001010100001101000001001111110011110100111011001110
01001101110011010100110011001100010010111100101101001010110010100100100111001001
01001000110010000100011111000111010001101100011001000101110001010100010011000100
01000011110000110100001011000010010000011100000101000000110000000011111110111111
00111110101111100011110110111101001111001011110000111011101110110011101010111010
00111001101110010011100010111000001101111011011100110110101101100011010110110101
00110100101101000011001110110011001100101011001000110001101100010011000010110000
00101111101011110010111010101110001011011010110100101100101011000010101110101011
00101010101010100010100110101001001010001010100000100111101001110010011010100110
00100101101001010010010010100100001000111010001100100010101000100010000110100001
00100000101000000001111110011111000111101001111000011101100111010001110010011100
00011011100110110001101010011010000110011001100100011000100110000001011110010111
00010110100101100001010110010101000101001001010000010011100100110001001010010010
00010001100100010001000010010000000011111000111100001110100011100000110110001101
00001100100011000000101110001011000010101000101000001001100010010000100010001000
00000111100001110000011010000110000001011000010100000100100001000000001110000011


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
Teehee



Joined: 05 Aug 2009
Posts: 568
Location: Brazil
Teehee
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
edfed



Joined: 20 Feb 2006
Posts: 4240
Location: 2018
edfed
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-2020, Tomasz Grysztar. Also on YouTube, Twitter.

Website powered by rwasa.