共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 跳转至页
回复
有奖活动 | |
---|---|
【EEPW电子工程师创研计划】技术变现通道已开启~ | |
发原创文章 【每月瓜分千元赏金 凭实力攒钱买好礼~】 | |
【EEPW在线】E起听工程师的声音! | |
“我踩过的那些坑”主题活动——第001期 | |
高校联络员开始招募啦!有惊喜!! | |
【工程师专属福利】每天30秒,积分轻松拿!EEPW宠粉打卡计划启动! | |
送您一块开发板,2025年“我要开发板活动”又开始了! | |
打赏了!打赏了!打赏了! |
打赏帖 | |
---|---|
电流检测模块MAX4080S被打赏10分 | |
【我踩过的那些坑】calloc和malloc错误使用导致跑飞问题排查被打赏50分 | |
多组DCTODC电源方案被打赏50分 | |
【我踩过的那些坑】STM32cubeMX软件的使用过程中的“坑”被打赏50分 | |
新手必看!C语言精华知识:表驱动法被打赏50分 | |
【我踩过的那些坑】杜绑线问题被打赏50分 | |
【我踩过的那些坑】STM32的硬件通讯调试过程的“坑”被打赏50分 | |
【我踩过的那些坑】晶振使用的问题被打赏100分 | |
【我踩过的那些坑】电感选型错误导致的处理器连接不上被打赏50分 | |
【我踩过的那些坑】工作那些年踩过的记忆深刻的坑被打赏10分 |