How to load Z-Reg.

Go To Last Post
3 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,
if I have an eeprom-segment like:

.eseg:

MyValues:
.db $12,$13,$14,$15,$16,$00,$00,$00

How can I load the Z-Reg correctly when using an atmel with 512Byte Eeprom - since there are more than 1 Byte to address the Eeprom?

Until now I used some code like:

ldi tmp2,0
out EEARH,tmp2 ; High-Byte of EEPROM-Adr.=0
ldi tmp1,MyValues
out EEARL,tmp1 ; Low-Byte of EEPROM-Adr.=tmp1

admin's test signature
 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi Michael,

The Z register is 16 bit. ie. It's made up of ZL (R30) and ZH (R31) pair.
So you can load 16 bit addresses into it.
Check out the data sheet under 'General Purpose Register File'

Cheers Jack

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

PS: Someone correct me if I'm wrong, but I didn't think you could address the eeprom directly with the Z register.
Using Z reg with LPM instruction addresses program memory.
Using Z reg with LD and ST plus derivative instructions, addresses data space. ie. R0 . . . .R31 plus I/O space and Sram.

Cheers Jack