Gotchas: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 450: | Line 450: | ||
Strangely enough, [[8080 Assembly]] uses a more sensible <code>PCHL</code> (set Program Counter equal to HL) to describe this function. So this gotcha is actually exclusive to Z80. |
Strangely enough, [[8080 Assembly]] uses a more sensible <code>PCHL</code> (set Program Counter equal to HL) to describe this function. So this gotcha is actually exclusive to Z80. |
||
===IN/OUT=== |
|||
Depending on how the Z80 is wired, ports can be either 8-bit or 16-bit. This creates somewhat confusing syntax with the <code>IN</code> and <code>OUT</code> commands. A system with 16-bit ports will use <code>BC</code> even though the assembler syntax doesn't change. Luckily, this isn't something that's going to change at runtime. The documentation will tell you how to use your ports. |
|||
<lang z80>ld a,&46 |
|||
ld bc,&0734 |
|||
out (C),a ;write &46 to port &0734 if the ports are 16-bit. Otherwise, it writes to port &34.</lang> |
|||
Unfortunately, this means that instructions like <code>OTIR</code> and <code>INIR</code> aren't always useful, since the B register is performing double duty as the high byte of the port and the loop counter. Which means that your port destination on systems with 16-bit ports is constantly moving! Not good! |