将堆栈指针从 ARM 汇编中的 4 个字节对齐 8 个字节 [英] Aligning a Stack pointer 8 byte from 4 byte in ARM assembly

查看:28
本文介绍了将堆栈指针从 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天全站免登陆