assemblytexas-instrumentsz80

When using z80 asm is there a difference between (HL) and (BC/DE)?


In the process of attempting to write assembly for my TI-84 PlusCE I came across an odd "bug". Consider the following code:

#include "includes\ti84pce.inc"

s_mem_start = saveSScreen

 .assume ADL=1
 .org userMem-2
 .db tExtTok,tAsm84CeCmp

 ;relevant portion
 ld HL, s_mem_start
 ld DE, 2
 ADD HL, DE
 ld D, H
 ld E, L

 ld A, (HL)
 call _PutC
 ld A, (DE)
 call _PutC
 ;/relevant portion

 ret

saveSScreen is a portion of free ram. _PutC is a rom call that prints the value of A to the screen. See this chart: http://tibasicdev.wikidot.com/83lgfont. I have confirmed the _PutC does not affect any registers. The output of this code to the screen is v[CursorInsertSecond]. (CursorInsertSecond is a character on the calculator). These are equivalent to the hex 03 or 73 and E5. I can't tell if the v is the regular v or the italic v.

Clearly (HL) and (DE) are accessing different parts of memory. This is also the same when using BC. The odd thing is I can't find this information recorded anywhere. It would seem a major detriment to only have one register pair for accessing memory. Indeed it has made my own code feel very bloated.

The final odd thing that I have noticed is that this only seems to apply when adding to HL. Consider this code: (Minus the header portion).

 ld HL, s_mem_start + 2
 ld DE, s_mem_start + 2

 ld A, (HL)
 call _PutC
 ld A, (DE)
 call _PutC

This results in the output vv. What could be going on here? Why do (HL) and (DE) give different outputs but only some of the time.


Solution

  • It turns out that the ti84plusce actually runs ez80 assembly. In ez80 assembly HL, BC, and DE are three bytes not two. My code only copied two of the bytes and thus the addresses got messed up.