Hi, I asked my question on stack overflow. I was wondering if you could help: https://stackoverflow.com/questions/63320698/when-using-z80-asm-is-there-a-difference-between-hl-and-bc-de
Confusingly, a register pair on the eZ80 is 24-bytes but each lone register (A, B, C, D, E, H, L) is 8 bits. It is not possible to write to the upper byte of the register pair using the 8-bit registers.
To solve your problem you have two options.

Using the stack to copy HL into DE.

Code:
```push hl pop de```

Or exchange values of HL with DE.

Code:
`ex de, hl`
On the ez80 in ADL=1 mode the register pairs are '24-bit', consisting of 3 x 8-bit portions if you will.

SavesScreen = 0D0EA1Fh so when you load that in HL the 'upper' byte contains 'D0'. You also set DE=2 or 000002, which means that '00' is in the DE upper byte.

As Brando mentioned an 8-bit register assignment like LD D,H \ LD E,L then you aren't altering these 'upper' bytes and your resultant address in DE = 00EA1F.

You can relplace the register assignment with PUSH HL \ POP DE as Brando suggested and this will have the desired effect.
What would be the best way to get those 24 bits into a specific memory location? The best I can think of right now is push the value onto the stack and then using the stack pointer to get 1 byte at a time. Is there a better way?
You can use ld (address),hl to store the three bytes of hl to a memory address. This also works for the other 24-bit registers.
Oh, cool thanks. For some reason, I thought that wouldn't work
Oh that was you who asked that question!
Are you looking for something like:

Code:
```  ld (address),hl ; store HL in little-endian at address  ld hl,(address) ; read the 3-byte value at address into HL ```

?
Yes that is what I was after. Will that work?

Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

»
» All times are UTC - 5 Hours

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum