Message board for the users of flat assembler.
> Main > best way of handling bits
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?
|31 Jan 2011, 02:10||
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.
|31 Jan 2011, 03:44||
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 stosw loop @b ret bitfield: times 256 db %-1
and see the result:
then, what is appearing?
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.
|10 Mar 2011, 00:27||
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.
|10 Mar 2011, 01:16||
edfed 10 Mar 2011, 11:07
|10 Mar 2011, 11:07||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.