02-25-2010, 03:33 AM
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).
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.
Binary AND:
Binary OR:
Binary XOR:
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.
8 bit result: bAND with 255
16 bit result: bAND with 65535
If you want the function, it's probably obvious to you. You could also use bNOT16 and bNOT8 listed in the previous thread - and if you always want 16 or 8 bit values, that's the smaller and faster route.
32 Bit Binary NOT:
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.
Binary AND:
Code:
Function bAND(a as uLong, b as uLong) as uLong
asm
POP BC ; something
EXX
POP HL ; return address
EXX
POP HL ; aL
POP DE ; aH
POP BC ; bL
LD A,B
AND H
LD H,A
LD A,C
AND L
LD L,A
POP BC ;bH
LD A,B
AND D
LD D,A
LD A,C
AND E
LD E,A
EXX
PUSH HL ; put return address back
EXX
end asm
END function
Binary OR:
Code:
Function bOR(c as uLong, d as uLong) as uLong
asm
POP BC ; something
EXX
POP HL ; return address
EXX
POP HL ; aL
POP DE ; aH
POP BC ; bL
LD A,B
OR H
LD H,A
LD A,C
OR L
LD L,A
POP BC ;bH
LD A,B
OR D
LD D,A
LD A,C
OR E
LD E,A
EXX
PUSH HL ; put return address back
EXX
end asm
END function
Binary XOR:
Code:
Function bXOR(e as uLong, f as uLong) as uLong
asm
POP BC ; something
EXX
POP HL ; return address
EXX
POP HL ; aL
POP DE ; aH
POP BC ; bL
LD A,B
XOR H
LD H,A
LD A,C
XOR L
LD L,A
POP BC ;bH
LD A,B
XOR D
LD D,A
LD A,C
XOR E
LD E,A
EXX
PUSH HL ; put return address back
EXX
end asm
END function
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.
8 bit result: bAND with 255
16 bit result: bAND with 65535
If you want the function, it's probably obvious to you. You could also use bNOT16 and bNOT8 listed in the previous thread - and if you always want 16 or 8 bit values, that's the smaller and faster route.
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