presh wrote: ↑Wed Mar 25, 2020 1:11 am
And to top it off, (C) is in brackets... which generally means a pointer is being referenced, like you'd find in OR (HL) or similar... that doesn't make sense, does it? BC is an address, not a pointer!!! Eh?? ARGH!!!!
Yeah, the Z80 mnemonics are a bit inconsistent. Mind that only the actual conventional
mnemonics are inconsistent; the instructions themselves are interpreted by the CPU in a very consistent manner. In fact, the CPU couldn’t operate if that weren’t the case. Remember, mnemonics are simple shortcuts intended for the ease of keeping track of what’s going on for the human programmer. The Z80 couldn’t care less about how they’re written.
So, IN A,(n) actually means “read a byte from port An (A being the high byte and n being the low byte) and store it in A.” You could just as well rewrite it as IN A,(An). Similarly, IN A,(C) could be written as IN A,(BC).
Regarding the parentheses, there are some inconsistencies there, too. For example, LD A,(HL) means “load the value stored in memory location pointed to by HL into A.” This makes sense—if HL has a value of $4000 and that memory location has a value of $53, then after the instruction LD A,(HL) is executed, the A register will hold $53. All is good. However, if you take an instruction like JP (HL), this logic breaks. One would assume that this means “jump to the address stored in memory locations pointed to by HL and HL+1” (an address is a two-byte value after all), but no, it actually means “jump to the address stored in the HL register pair.” It would be more reasonable to write it as JP HL.
As for the undocumented instructions, well, it is precisely because they’re undocumented that there’s no conventional way of writing them, and each assembler will use a slightly different notation (although, most will try to handle as many as is technically feasible). Take IN (C), for example. Another widely used mnemonic for it is IN F,(C). What this instruction does is it reads a byte from port BC, but instead of loading that value into any particular register, it only analyzes it and changes the flags (i.e. affects the F register). Mind that any IN instruction does that anyway, except that IN F,(C) discards the actual value. Again, it could just as well be written as IN (BC) or IN F,(BC).
Similarly, the undocumented instruction SLL A is sometimes written as SL1 A, because it writes a one into Bit 0 of A. I guess this is done by analogy with SRL (shift right logical) where a zero is written to Bit 7.
Don’t get too hung up on the mnemonics themselves. If instead of IN A,(C) you want to hand-assemble your code and write DEFB $ED,$78—I’m not going to stop you.