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

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

[avr-gcc-list] How to get low byte off a function address?


From: Wouter van Gulik
Subject: [avr-gcc-list] How to get low byte off a function address?
Date: Sat, 19 Jan 2008 16:15:35 +0100

Dear list,

How do I do this:

main.c
=============================================
void foo(void) {
}

char table[2] = {
    (foo),     
    (foo),     
};

int main(int argc, char* argv[]) 
{
        int adr = table[argc]+0x3F00;
        ((void (*) (void))adr)();
        return 0;
}=============================================

It gives:

main.c:5: warning: initialization makes integer from pointer without a cast
main.c:5: error: initializer element is not computable at load time
main.c:5: error: (near initialization for 'table[0]')
main.c:6: warning: initialization makes integer from pointer without a cast
main.c:6: error: initializer element is not computable at load time
main.c:6: error: (near initialization for 'table[1]')

Why is it not computable? Why is it when I make it 16 bits?

I first wanted to implement this in assembler.
But I got all sorts off error, mainly gas refusing to see I only want 8
bits, not 16.
So I figured I go and try this in C, but I can't get it done.

You might wonder why on earth would I want to such a strange thing?
Well I have a very small bootloader so I know all my functions are within
the 512byte/256 word boundary. And I there for I have no need to store the
full 16-bit address (in order to keep my bootloader small).
I just need the low byte of the address.

How do I do such a thing? Using the lower 8 bits is possible when loading a
register so why not in a table?

In assembler I tried this:
           .byte lo8(foo)
         .byte pm_lo8(foo)    
         .byte lo8(pm(foo))    

But all are with the same result:
Error: illegal relocation size: 1                              
Error: junk at end of line, first unrecognized character is `('

Hope you can help

Wouter





reply via email to

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