Yahoo Groups archive

AVR-Chat

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

Thread

Reading tables from flash

Reading tables from flash

2006-09-29 by Mark Jordan

ldi ZH, high(TABLE*2)
	ldi ZL,  low(TABLE*2)

	lpm temp, Z+
	lpm temp, Z+
	lpm temp, Z+
	lpm temp, Z+
	lpm temp, Z+

	Question:

	- What is the current value of ZH:ZL?

	Thanks.
	Mark Jordan

Re: [AVR-Chat] Reading tables from flash

2006-09-29 by David VanHorn

>
>
>        ldi ZH, high(TABLE*2)
>        ldi ZL,  low(TABLE*2)
>
>        lpm temp, Z+
>        lpm temp, Z+
>        lpm temp, Z+
>        lpm temp, Z+
>        lpm temp, Z+
>
>        Question:
>
>        - What is the current value of ZH:ZL?


You could just walk that through the sim and see how it works.
Z increments byte by byte, not word, so it's 2.5 words up from the start of
TABLE

When you set Z, you're loading in Table*2, and the LSB selects which byte
you get, 0=low, 1=high
This is why we have the ELPM instruction, for the larger chips.


[Non-text portions of this message have been removed]

Re: [AVR-Chat] Reading tables from flash

2006-09-29 by Mark Jordan

On 29 Sep 2006 at 10:34, David VanHorn wrote:

> >
> >
> >        ldi ZH, high(TABLE*2)
> >        ldi ZL,  low(TABLE*2)
> >
> >        lpm temp, Z+
> >        lpm temp, Z+
> >        lpm temp, Z+
> >        lpm temp, Z+
> >        lpm temp, Z+
> >
> >        Question:
> >
> >        - What is the current value of ZH:ZL?
> 
> 
> You could just walk that through the sim and see how it works.
> Z increments byte by byte, not word, so it's 2.5 words up from the start of
> TABLE
> 
> When you set Z, you're loading in Table*2, and the LSB selects which byte
> you get, 0=low, 1=high
> This is why we have the ELPM instruction, for the larger chips.
> 
> 

	Hi David, thanks for the explanation.
	My problem is how to find the LPM passed the end of table
by looking at the ZH:ZL register.

	I tried the code below, but it is not working:

read:
	lpm register, Z+

	ldi temp, high(ENDTABLE*2)
	cp ZL, low(ENTABLE*2)
	cpc ZH, temp
	brlo read

	ret


TABLE:
.db "Hello world!"
.db "Hello world!"
.db "Hello world!"
.db "Hello world!"
.db "Hello world!"
.db "Hello world!"
ENDTABLE:

Re: [AVR-Chat] Reading tables from flash

2006-09-29 by David VanHorn

>
>        Hi David, thanks for the explanation.
>        My problem is how to find the LPM passed the end of table
> by looking at the ZH:ZL register.


Ah.  Ok.

Normally, I use null terminated strings, and tables of definite length, so I
haven't had to do that in a while.


       I tried the code below, but it is not working:
>
> read:
>        lpm register, Z+
>
>        ldi temp, high(ENDTABLE*2)
>        cp ZL, low(ENTABLE*2)
>        cpc ZH, temp
>        brlo read



damn gmail, can't use tabs..

ldi  YL,low(EndTable*2)
ldi  YH,high(EndTable*2)
sub YL,ZL
sub YH,ZH   ;If addresses are equal, then result is 0000h
or  YL,YH    ;single byte, we don't care what it is, as long as it's <>0
and  YL,YL  ;May not be needed, if Or sets the Z flag, I don't remember
offhand
breq wherever


[Non-text portions of this message have been removed]

Re: [AVR-Chat] Reading tables from flash

2006-09-29 by Mark Jordan

I found the problem. It was on another part of the code.

	Thanks,
	Mark Jordan
Show quoted textHide quoted text
On 29 Sep 2006 at 11:44, David VanHorn wrote:

> >
> >        Hi David, thanks for the explanation.
> >        My problem is how to find the LPM passed the end of table
> > by looking at the ZH:ZL register.
> 
> 
> Ah.  Ok.
> 
> Normally, I use null terminated strings, and tables of definite length, so I
> haven't had to do that in a while.
> 
> 
>        I tried the code below, but it is not working:
> >
> > read:
> >        lpm register, Z+
> >
> >        ldi temp, high(ENDTABLE*2)
> >        cp ZL, low(ENTABLE*2)
> >        cpc ZH, temp
> >        brlo read
> 
> 
> 
> damn gmail, can't use tabs..
> 
> ldi  YL,low(EndTable*2)
> ldi  YH,high(EndTable*2)
> sub YL,ZL
> sub YH,ZH   ;If addresses are equal, then result is 0000h
> or  YL,YH    ;single byte, we don't care what it is, as long as it's <>0
> and  YL,YL  ;May not be needed, if Or sets the Z flag, I don't remember
> offhand
> breq wherever
> 
> 
> [Non-text portions of this message have been removed]
> 
> 
> 
>  
> Yahoo! Groups Links
> 
> 
> 
> 
> 
> 
> 
> 
>

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.