Yahoo Groups archive

AVR-Chat

Index last updated: 2026-04-28 22:41 UTC

Message

Re: [AVR-Chat] Reading from flash in Assembly

2004-12-03 by Dave VanHorn

At 06:32 PM 12/3/2004, John Samperi wrote:


>At 10:54 AM 3/12/04 -0000, you wrote:
> >
> >Ok, and the final soloution is ;-
> >
> >mov r30, step
> >ldi r31, high(array<<1)
> >add r31, num
> >lpm r18, z
> >out portd, r18
> >
> >As I'm only using Bytes not Words, I didn't need to left shift the ZL (r30)
> >value.
>
>But DOES IT WORK? :-) The flash is in 2 byte lots (16 bit) that is the reason
>you need to multiply by 2 to get to the address.

Doesn't look entirely sane to me..

 >mov r30, step
 >ldi r31, high(array<<1)

Not sure what step is, but we are now pointing at high(Array*2)+Step

 >add r31, num

Ok, adding offset, but this assumes that Step + num will never be > 255.

 >lpm r18, z
 >out portd, r18

Conventional..


What I would do, is this:

ldi     zl,low(Array*2) ;Point at the array
ldi     zh,high(Array*2)

clr     TEMP2 ;or any suitable register
add     zl,step         ;16 bit op
adc     zh,TEMP2

add     zl,num          ;16 bit op
adc     zh,TEMP2

lpm     r18,z
out     portd,r18

But I'm not sure how step is used here, so the first 16 bit add might not 
really be the right thing.

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.