Search code examples
cassemblyinline-assemblywinavr

Trying to define variables to specific memory locations


Hey, im using WinAVR and programing an ATMEGA32 in C.
Basically, I want to link my C program to asm via the:

asm(" ") command.

Im trying to define memory locations in C to exact memory locations so that I can then access them within the asm command line.

I have 5 variables:

unsigned char var1, var2, var3, var4, var5;

I know I could use pointers to a memory location, but im unsure how to do this.
Any help would be appreciated.
Thanks,
Oliver.


Solution

  • This method is completely compiler-independent, simple, and straightforward:

    #define var1 (*(volatile unsigned char *)0xDEADBEEF)
    #define var2 (*(volatile unsigned char *)0xDECAFBAD)
    #define var3 (*(volatile unsigned char *)0xBADC0DE)
    

    etc.