8515 Code question

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

I do not understand why these two chunks of code do not produce the same reult. I am pulling a value from memory and putting it on the Pins.

; this works
ldi ZH,high(Ascii*2)
ldi ZL, low(Ascii*2) ; init Z-pointer to storage bytes
adiw ZL,4 ; Z+offset
lpm ; Pull value directly
com r0 ; for Led display
out PortB,r0 ; shows 0x66

; this does not?
ldi ZH,high(Ascii*2)
ldi ZL, low(Ascii*2) ; init Z-pointer to storage bytes
ldd Tmp,Z+4 ; pull value @ offset
com Tmp ; for Led display
out PortB,Tmp ; shows 0xFF

Ascii:
;Digit 0 1 2 3 4 5 6 7 8 9
.db 0x3f, 0x06, 0x5b, 0x4f, 0x66, 0x6d, 0x7d, 0x27, 0x7f, 0x6f

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

LPM instruction is for accessing program memory (usually retrieving constants from code segment).
LDD, et al. is for accessing data memory.
AVR is Harvard architecture; code space is logically distinct from data space.

admin's test signature