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 Larry Barello

It depends, John: if you use GCC you can BYTE align stuff in FLASH and then
you need the BYTE address, which, as it happens, is what GCC provides.
Other tools, notably the Atmel Assembler, doesn't allow you to BYTE align
stuff in flash.  You need to align stuff on WORD (even) addresses.  However,
the LPM instruction will happily take BYTE addresses and fetch the correct
byte into your destination register.

So, if in the example, the array was WORD aligned (which it was), then
nothing more needs to be done than the left shift (x2) + the BYTE offset of
the data the user is interested in.  The LPM instruction takes care of
everything else.

Cheers!

-----Original Message-----
From: John Samperi [mailto:samperi@ampertronics.com.au]
Sent: Friday, December 03, 2004 3:33 PM
To: AVR-Chat@yahoogroups.com
Subject: Re: [AVR-Chat] Reading from flash in Assembly



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.

What happens if the data is the 2nd byte of the array? It seems to me that
you need at least 1 multiplication and 2 16 bit additions to get it working
anywhere in  flash. If the above works well I have to redo some of my
code that gets the data from a character set lookup table (224 rows, 7
columns).

I don't quite understand how it would work... but then again I may have it
all wrong as I don't have the original post anymore.

Regards

John Samperi

******************************************************
                        Ampertronics Pty. Ltd.
  11 Brokenwood Place Baulkham Hills, NSW 2153 AUSTRALIA
         Tel. (02) 9674-6495       Fax (02) 9674-8745
               Email: samperi@ampertronics.com.au
                 Website  http://www.ampertronics.com.au
* Electronic Design   * Custom Products   * Contract Assembly
******************************************************





Yahoo! Groups Links

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.