开发者

Trying to define variables to specific memory locations

Hey, im u开发者_Go百科sing 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.


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.


You can access memory locations by their C variable names with inline assembler using GCC. Please refer to the AVR-GCC Inline Assembler Cookbook for more information. You can also place C variables at exact memory locations using compiler extensions or linker scripts. However, the whole point of compilers and assemblers is so that we don't have to manage tedious details like that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜