I am trying to remove the interrupt vector table in my program to reduce the flash memory usage.
I have successfully used the -nostartfiles
flag, which removes a lot of assembly code in the output.
To use the program, I have to set the stack pointer. I found this code to do so:
asm volatile ( ".set __stack, %0" :: "i" (RAMEND) );
But when compiled, it does nothing, while other assembly code like
asm volatile ( "clr __zero_reg__" );
asm volatile ( "rjmp main");
Does work.
This is my current C code:
void __init(void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
void __init(void)
{
asm volatile(".set __stack, %0" :: "i" (RAMEND) );
asm volatile ( "clr __zero_reg__" );
asm volatile ( "rjmp main");
}
Which compiles to assembly (the 7892 and 7894 lines):
void __jMain(void) __attribute__ ((naked)) __attribute__ ((section (".init9")));
void __jMain(void)
{
asm volatile(".set __stack, %0" :: "i" (RAMEND) );
asm volatile ( "clr __zero_reg__" );
7892: 11 24 eor r1, r1
asm volatile ( "rjmp main");
7894: 02 c0 rjmp .+4 ; 0x789a <main>
}
Why isn't the .set __stack
compiled? Am I missing some compiler flag? Have tried a lot of things.. Also reviewed bootloaders with the same piece of code who are doing the same thing, but somehow, mine does not compile correctly.