02-25-2010, 09:12 AM
britlion Wrote:Here are more general purpose functions for AND, OR and NOT. They work with Byte, Integer or Long types (the function is long, but the cast works upscale).This code is already implemented in the library-asm directory (see neg32.asm).
A binary NOT is tougher - what bits do you invert? If you send me 8, and I invert 32 is that what you wanted?
(of course, you could bAND the result into the last 8 or 16 bits)
These functions are very similar, of course.
Here's the 32 bit NOT function. This is the one that's tricky. If you want a NOT in 8 bits, do bAND(255,bNOT32(num)) - in other words, AND it to cut the length you want; or you are going to be confused at the result being a LOT bigger than you wanted.
[...]
32 Bit Binary NOT:
Code:FUNCTION FASTCALL bNOT32(g as uLong) as uLong
asm
LD A,D
CPL
LD D,A
LD A,E
CPL
LD E,A
LD A,H
CPL
LD H,A
LD A,L
CPL
LD L,A
end asm
END FUNCTION
In fact, bitwise operators were planned a long time ago, but I won't add new features until the compiler bugs are completely fixed.
You should not try to implement this code (I have already done so, in a separated file!), because they won't be functions, but operators. The compiler will insert them inline, which is faster than a function call, so instead of: bAND(X, Y) you will do X bAND Y.
I already have the code for integers (of any size) bitwise operators, and I think It's quite optimal. :!:
So, It's better to wait until it is released, and then try to optimize it by looking at librayasm/ directory.