[Top][All Lists]

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

Re: [avr-gcc-list] Jmp'ing to address / 2?

From: Ned Konz
Subject: Re: [avr-gcc-list] Jmp'ing to address / 2?
Date: Wed, 04 Oct 2006 21:28:48 -0700
User-agent: Thunderbird (Macintosh/20060909)

Stuart Whelan wrote:
Hi Folks,

I am using gcc 3.4.4 and avr-libc 1.4.4 on win32....

I have been using the CodeVision compiler for a long time, but have decided to port my projects to gcc-avr.

My application jumps to the bootloader on receipt of jump to bootloader command, but the jmp I am using seems to be doing strange things. I cut it done down to the smallest test:

        asm volatile("jmp 0x1c00"::);

And compiled it with:

avr-gcc -mmcu=atmega16 -o foo.obj foo.c
And the jmp command comes out as:
  96:   0c 94 00 0e     jmp     0x1c00 <__stack+0x17a1>

Now if I read that correctly, it is jmp'ing to 0e00, not 1c00.. I notice that 0e00 is 1c00/2...

Jumps are to word addresses. You can't jump to an odd address, so call/jmp (at the processor level) are in terms of words (not bytes).

When I step through this in the debugger, the program counter does indeed jump to 0e00, not 1c00.

That's correct.

The GNU toolchain (avr-gcc and avr-as, anyway) uses byte addresses.

The AVR uses word addresses for program memory (which is more than 1 byte wide).

Compare the code generated for the following jump:

typedef void (* funcptr) (void);
goto *(funcptr)0x1c00;  // a gcc extension; should do what you want:
  a4:   e0 e0           ldi     r30, 0x00       ; 0
  a6:   fc e1           ldi     r31, 0x1C       ; 28
  a8:   09 94           ijmp

Ned Konz

reply via email to

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