.org的c语言中的等效语句是什么? [英] What is the equivalent statement in c language for .org ?

查看:311
本文介绍了.org的c语言中的等效语句是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Kinetis Design Studio IDE和编程为MKE02Z64VLD2(Kinetis E系列)的处理器。该处理器的闪存区域为0X0000_0000至0X07FF_FFFF。我的代码是用C语言编写的。我需要将一段代码放入此处理器的闪存空间。如果是汇编,那么我们使用



 .org 0X0000_0000 {CODE} 





其中0X0000_0000是闪存空间的起始地址。因此,在.org语句之后编写的代码将被写入起始地址为0X00000000的内存空间。



它在C中的等效语句是什么?



我尝试了什么:



我尝试使用PRAGMA标签,但我不知道是否正在工作。

main()

{

#pragma section 0X00000000;

示例代码;

}

pragma标签是否适用于我使用的IDE?

解决方案

编译器生成可重定位目标文件然后链接。虽然C编译器可能有一个选项(查看编译器的手册),但更有可能将固定的起始地址传递给链接器或在某个配置文件中定义(可能是特定于处理器的配置文件)。 IDE的项目设置中可能还有一个选项。



如果使用的编译器是GCC,并且有一个选项来指定地址,则不会使用 pragma 语句,但 __ attribute __()语句。一项快速的网络研究发现使用gcc定义绝对地址的变量Eclipse上的MCU [ ^ ]描述如何在固定地址存储变量。因此,功能应该有类似的方式。



您可能会在相关论坛中提出更好的帮助,例如空间:Kinetis Design Studio |恩智浦社区 [ ^ ]

I am using Kinetis Design Studio IDE and the Processor on which am programming is MKE02Z64VLD2 (Kinetis E series). The Flash memory area of this processor is 0X0000_0000 to 0X07FF_FFFF . My code is in C language. I need to put a piece of code into the flash memory space of this processor. If its Assembly, then we use

.org 0X0000_0000 {CODE} 



where 0X0000_0000 is the starting address of the flash space. So the code written after the .org statement will be written to memory space whose starting address is 0X00000000.

What is its equivalent statement in C ?

What I have tried:

I tried using PRAGMA tags but I dont know whether it is working.
main()
{
#pragma section 0X00000000;
sample code;
}
Will pragma tags work for the IDE which I use ?

解决方案

A compiler generates relocatable object files which are then linked. While there might be an option for the C compiler (check the manual for your compiler), it is more probable that a fixed start address is passed to the linker or defined in some configuration file (probably a processor specific config file). There may be also an option in the project settings of the IDE.

If the used compiler is GCC and there is an option to specify the address it would not use a pragma statement but an __attribute__() statement. A quick web research found Defining Variables at Absolute Addresses with gcc | MCU on Eclipse[^] describing how to store variables at fixed addresses. So there should be a similar way for functions.

You might get better help asking in a related forum like Space: Kinetis Design Studio | NXP Community[^].


这篇关于.org的c语言中的等效语句是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆