共2条
1/1 1 跳转至页
require8,preserve8 麻烦板主:require8和preserve8到底怎么回事?
问
实战红书中114页有关ATPCS的要求使用preserve8来保证8位对齐.
我试验了一下,在startup.s中用了这两个指令,不论require8和preserve8都不能保证堆栈为8字节对齐.我的工程C和汇编互相调用,没用这两伪指令程序也正常,到底这两个指令有什么用,我参考了好多资料,得不到合理的解释.谢谢
答 1: 自己做答啦,斑竹忙些啥呢?c和汇编有8位对齐的要求,这两个伪指令可以满足此要求,存在REQUIRE8<——> PRESERVE8的对应关系,但不是说有一个REQUIRE8就要有一个 PRESERVE8,如果是一个c文件和一个汇编文件的调用,也就涉及一个PRESERVE8或者是一个REQUIRE8, 以下剪自ADS1.2中PDF,就很清楚,由此可见,最好不要使用LDRD 或 STRD。
LDRD and STRD instructions (double-word transfers) only work correctly if the address they access is 8-byte aligned.
If your code includes LDRD or STRD transfers to or from the stack, use REQUIRE8 to instruct the linker to ensure that your code is only called from objects that preserve 8-byte alignment of the stack.
If your code preserves 8-byte alignment of the stack, use PRESERVE8 to inform the linker.
The linker ensures that any code that requires 8-byte alignment of the stack is only called, directly or indirectly, by code that preserves 8-byte alignment of the stack.
另外,REQUIRE8和PRESERVE8并不完成8 byte 对齐的操作,对齐由ALIGN完成。
我试验了一下,在startup.s中用了这两个指令,不论require8和preserve8都不能保证堆栈为8字节对齐.我的工程C和汇编互相调用,没用这两伪指令程序也正常,到底这两个指令有什么用,我参考了好多资料,得不到合理的解释.谢谢
答 1: 自己做答啦,斑竹忙些啥呢?c和汇编有8位对齐的要求,这两个伪指令可以满足此要求,存在REQUIRE8<——> PRESERVE8的对应关系,但不是说有一个REQUIRE8就要有一个 PRESERVE8,如果是一个c文件和一个汇编文件的调用,也就涉及一个PRESERVE8或者是一个REQUIRE8, 以下剪自ADS1.2中PDF,就很清楚,由此可见,最好不要使用LDRD 或 STRD。
LDRD and STRD instructions (double-word transfers) only work correctly if the address they access is 8-byte aligned.
If your code includes LDRD or STRD transfers to or from the stack, use REQUIRE8 to instruct the linker to ensure that your code is only called from objects that preserve 8-byte alignment of the stack.
If your code preserves 8-byte alignment of the stack, use PRESERVE8 to inform the linker.
The linker ensures that any code that requires 8-byte alignment of the stack is only called, directly or indirectly, by code that preserves 8-byte alignment of the stack.
另外,REQUIRE8和PRESERVE8并不完成8 byte 对齐的操作,对齐由ALIGN完成。
共2条
1/1 1 跳转至页
回复
有奖活动 | |
---|---|
【有奖活动】智能可穿戴设备AR/VR如何引领科技新潮流! | |
奖!发布技术笔记,技术评测贴换取您心仪的礼品 | |
【有奖活动】震撼来袭!这场直播将直击工程师的心灵! | |
“我想要一部加热台”活动,不花钱赢取开发好工具!活动开始了哦 | |
【有奖活动】伙伴们:您的“需求”解决了吗? |
打赏帖 | |
---|---|
如何实现基于NXPiMX.RT1021的BH1730采集被打赏50分 | |
【换取手持数字示波器】AHT10温度检测分享被打赏40分 | |
【换取手持数字示波器】ACM32F070开发板点亮LCD屏和触控按键,串口,ADC被打赏40分 | |
【换取手持数字示波器】ACM32F070LCD屏和触控按键功驱动蜂鸣器分享被打赏40分 | |
【换取手持数字示波器】国民技术PWM功能知识分享被打赏40分 | |
【换取手持数字示波器】放大器运放知识分享被打赏40分 | |
【分享评测,赢取加热台】+开关电源AC输入知识分享被打赏30分 | |
【换取手持数字示波器】N32G430点亮数码管与串口打印、ADC被打赏40分 | |
老胖子聊电路--分析一个反馈电路被打赏50分 | |
【换取手持数字示波器】+点亮WS2812RGB灯被打赏50分 |