Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Logical Bitwise Functions - AND, OR, XOR, NOT
#5
> Do Fastcall get the argument (sentin) as A (Accumulator) value if argument is ubyte, and HL if it is uinteger?

Exactly right. You're allowed one thing sent in with fastcall - a byte arrives as A and a 16 bit value arrives as HL. For that matter a LONG arrives as DEHL.

Sending out works the same way. A byte return has to be in A, and an Integer return has to be in HL.

Let's talk about AND:

bAND (byte1, byte2) gets two bytes as a standard ZX BASIC function.

It puts them BOTH into a uinteger and sends them to a fastcall. In effect it puts them in HL. It makes H = byte1 and L=Byte 2.

bANDHL does (H AND L) effectively. But there's no z80 assembler option to do that, we can only AND A with something.

so it copies H into A, and then AND's A with L; which is the same as (H AND L) effectively.

NOT:
The z80 assembly instruction CPL (which stands for 'complement') swaps all the 1's for 0's and all the 0's for 1's - it's a binary NOT basically. There is no z80 assembly instruction called 'NOT' - but this one means the same thing in this case. Doing this is one way of making a number negative in binary. It's a little technical, but you could look at wikipedia for more on that:

<!-- m --><a class="postlink" href="http://en.wikipedia.org/wiki/Signed_number_representations#Ones.27_complement">http://en.wikipedia.org/wiki/Signed_num ... complement</a><!-- m -->

I think I've worked out how to use standard call now as well. So, I think I might be able to do a function that does it all. Still need to work out how return values on things like Long integers work though. It's probably the stack. Also what happens if you send bNOT (uByte) to a function expecting bAND(Long)? What would you want it to do?

I have a question: What are you using this for? What do you need LONG AND to work with that wouldn't work with byte size chunks?


Oh: In the spirit of trying to get everything better documented, I added documentation for FASTCALL to the wiki: <!-- m --><a class="postlink" href="http://www.boriel.com/wiki/en/index.php/ZX_BASIC:FastCall">http://www.boriel.com/wiki/en/index.php ... C:FastCall</a><!-- m -->

I've been adding bits to the wiki command page as time goes by and I needed to work something out.
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)