在 ARM 程序集中将堆栈指针从 4 字节对齐 8 字节 [英] Aligning a Stack pointer 8 byte from 4 byte in ARM assembly

查看:16
本文介绍了在 ARM 程序集中将堆栈指针从 4 字节对齐 8 字节的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将堆栈指针对齐到 8 字节,现在在 ARM 中对齐为 4 字节.根据我的理解,如果堆栈指针指向某个地址,如 0x4 、0x8、0x12 和 0x16 等,则它是 4 字节对齐的.

How do I align a stack pointer to 8 byte which is now 4 byte aligned in ARM .As per my understanding stack pointer is 4 byte aligned if it points to some address like 0x4 ,0x8,0x12 and 0x16 so on.

因此,将堆栈指针对齐为 8 字节意味着它应该指向诸如 0x8 、0x16 、0x24 和 0x32 等地址.

So ,aliging a stack pointer to 8 byte means it should point to addresses like 0x8 ,0x16 ,0x24 and 0x32 and so on.

现在如何将 4 字节堆栈指针对齐到 8 字节对齐指针?

Now how Do I aligned 4 byte stack pointer to 8 byte aligned pointer?

推荐答案

不要尝试自己手动对齐sp,而是push多一个寄存器来对齐.例如,而不是

Don't try to align sp manually yourself, instead push one more register to get alignment. For example instead of

push {r3, r4, lr}

在列表中再添加一个寄存器以轻松对齐到 8.

add one more register to the list to get alignment to 8 easily.

push {r1, r3, r4, lr}

这可能感觉像是额外的内存访问,但通常缓存使用比原生字长更宽的位向量.

This may feel like extra memory access but in general caches works with wider bit vectors than native word sizes.

另一个注意事项是,如果您不进行外部调用或接收,则无需强迫自己正确进行堆栈对齐.因此,如果您有封闭的盒组装例程,它不调用外部世界或接收一些,只要它不占用您自己的负载,您就可以忍受损坏的堆栈对齐.

Another note is also, you don't need to force yourself to get stack alignment right if you are not doing external calls or receiving. So if you have closed box assembly routine which doesn't make calls to external world or receive some, you can live with broken stack alignment as long as it doesn't bite your own loadings.

这篇关于在 ARM 程序集中将堆栈指针从 4 字节对齐 8 字节的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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