avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] rjmp confusion


From: Richard Urwin
Subject: Re: [avr-gcc-list] rjmp confusion
Date: Wed, 11 Feb 2004 21:47:35 +0000
User-agent: KMail/1.5.3

On Wednesday 11 Feb 2004 8:45 pm, you wrote:
> On Wednesday, February 11, 2004, at 12:17 PM, Richard Urwin wrote:
> > On Wednesday 11 Feb 2004 7:19 pm, Simon Han wrote:
> >> Hello,
> >>    Based on AVR instruction set documentation, rjmp is defined to be
> >> "relative jump to an address within PC - 2K + 1 and PC + 2K
> >> (words)". Then it says that "for AVR microcontrollers with Program
> >> memory not exceeding 4K words this instruction can address the
> >> entire memory from EVERY address location".  I capitalize the word
> >> I am confused about. How can a rjmp instruction located at flash
> >> memory 3.5K jump back to flash memory location at 0.5K?  This will
> >> require rjmp (-3K). Does avr-gcc generate code at some middle
> >> point (say flash memory location at 2K) to solve this problem?
> >
> > No. The program memory is self-contained, so jumps off the end of
> > the address space will wrap around to the other end.
> >
> > 0xfff + 1 = 0x000
> >
> > 3.5K + 1K = 0.5K   QED
> >
> > in fact:
> >
> > 3.5K = 0x0e00
> > 1K = 0x0400
> > 0.5K = 0x0200
> >
> > 0x0200 - 0x0e00 = 0xf400
> >
> > 0xf400 has obviously overflowed, but to twelve bits it is 0x400, ie
> > +1K.
> >
> > --
> > Richard Urwin
>
> Now, I am fully convinced it will work.  :-)
> Let's consider following situation.  I use "-mshort-calls" in
> atmega128 to force rjmp when compiling a loadable binary.  That is,
> we have a kernel running in atmega128 and we would like to load
> binary during runtime.  Will above calculation should hold?
> For example, let's say this module is 4K words in size and is loaded
> in atmega128 at address 20K word.  What will rjmp (1K word) in module
> address 3.5K (atmega128 address 23.5K) go?  Will it go to 23.5 + 1 =
> 24.5 K word, or will it go to 23.5 - 3 = 20.5K word?  My
> understanding is that address wrapping is not valid anymore.  Does
> this mean that the maximum size of module can only be 2K words?

When the memory space is over 4K then wrapping still happens near the 
ends, but it is not as usefull.
I don't know the mega128, but let's say it has 32K memory. Over 30K you 
can jump to addresses around 0 and vice-versa. But otherwise you are 
stuck with the +/- 2K.
So in your example it would jump to 24.5K

If your program was only 4K long then you could duplicate it throughout 
the mega128 memory, at 4K intervals, and it would act as if memory was 
4K long, the code at 24.5K would be the same as that at 20.5K. But 
don't. Nothing is worth that confusion.

-- 
Richard Urwin


reply via email to

[Prev in Thread] Current Thread [Next in Thread]