历史上的今天
今天是:2025年02月03日(星期一)
2021年02月03日 | 关于arm汇编中的align
2021-02-03 来源:eefocus
经常会看到arm-linux汇编中有如下的指令:
.align n
它的含义就是使得下面的代码按一定规则对齐,.align n 指令的对齐值有两种方案,n 或 2^n ,各种平台最初的汇编器一般都不是gas,采取方案1或2的都很多,gas的目标是取代原来的汇编器,必然要保持和原来汇编器的兼容,因此在gas中如何解释 .align指令会显得有些混乱,原因在于保持兼容。
arm-linu是按照2^n的方案对齐的,需要说明的是这个对齐和ld-script里的对齐不同,不是一会事。下面的英文就不同平台的对齐进行了说明:
版本2.11.92.0.12的gas的info(Mandrake 8.2上的)这样说:
The way the required alignment is specified varies from system to system. For the a29k, hppa, m68k, m88k, w65, sparc, and Hitachi SH, and i386 using ELF format, the first expression is the alignment request in bytes. For example `.align 8' advances the location counter until it is a multiple of 8. If the location counter is already a multiple of 8, no change is needed.
For other systems, including the i386 using a.out format, and the arm and strongarm, it is the number of low-order zero bits the location counter must have after advancement. For example `.align 3' advances the location counter until it a multiple of 8. If the location counter is already a multiple of 8, no change is needed.
从这段文字来看,ARM的.align 5就是2的5次方对齐,也就是4字节对齐,通过反汇编也可以看出对齐方式:
.align 5
stmfd sp!, {r0 - r3, lr}
mov r0, ip
ldmfd sp!, {r0 - r3, pc}^
.align 5
stmfd sp!, {r0 - r3, lr}
mov r0, ip
mov ip, r0
ldmfd sp!, {r0 - r3, pc}^
反汇编:
00000000 <.text>:
0: e92d400f stmdb sp!, {r0, r1, r2, r3, lr}
4: e1a0000c mov r0, ip
8: e8fd800f ldmia sp!, {r0, r1, r2, r3, pc}^
...
20: e92d400f stmdb sp!, {r0, r1, r2, r3, lr}
24: e1a0000c mov r0, ip
28: e1a0c000 mov ip, r0
2c: e8fd800f ldmia sp!, {r0, r1, r2, r3, pc}^
30: e1a00000 nop (mov r0,r0)
34: e1a00000 nop (mov r0,r0)
38: e1a00000 nop (mov r0,r0)
3c: e1a00000 nop (mov r0,r0)
一些忠告:
In the future, everytime when you build an elf file, you need meantime created your map file. And then you will avoid mistakes like this align.
Also, please also pick up some linker script knowlege part. For embedded system, we frequently play the linker script to tune an image, for example, align some special section and so on for protection or/and cache purpose. wish helpful
以上就是我在网上找到并总结的有关.align的一些内容
史海拾趣
|
大家好!我早上收到的东西,打开包装,接通电源,切换开关打到NOR FLASH一端,然后开机启动,白屏一下就黑屏了。关机,开关打到NAND FLASH一端,再开机,白屏,没反应。。 我按照说明书上的操作,调出超级终端,接收到的数据和说明书上 ...… 查看全部问答> |
|
我的手机是200万象素的,照相摄影的时候分辨率还是蛮好的。。 但是摄像的时候,分辨率只有120×160了,郁闷啊。。 我是用Directshow来采集数据的。。。 枚举视频格式的代码如下:hr = m_pCaptureBuilder->FindInterface(&PIN_CATEGORY_CAPTURE, ...… 查看全部问答> |
|
我做了一个对话框程序 当点击按键2时。整个程序全部退出。请哪位大侠给个列子哦。请问下面***处的代码应该怎么写哦! BOOL CYaluDlg::PreTranslateMessage(MSG* pMsg) { CCollectDate dlg; ...… 查看全部问答> |
|
我用ATL开发了ActiveX控件,直接在模拟器运行 class ATL_NO_VTABLE CMainObject : public CComObjectRootEx, public CComCoClass, public IDispatchImp ...… 查看全部问答> |
|
EVC中怎么将“中国”的Unicode编码内码字串“4E2D56FD”转换到ANSI的“中国”内码字串?? EVC中怎么将“中国”的Unicode编码内码字串“4E2D56FD”转换到ANSI的“中国”内码字串??就是说: 1、输入:String := \'4E2D56FD\';(“中国”的Unicode内码) 2 ...… 查看全部问答> |
|
...input a;output b;reg b;always @ (a)if(a)b=1\'b1;elseb=1\'b0;------------------------------------------------------------...input a;output b;assign b= a ? 1\'b1 : 1\'b0; 两段代码书写方法不一样。综合结果都是一个选择器。 ...… 查看全部问答> |
|
#include #include #define uchar unsigned char #define uint unsigned int sbit sda=P2^1; sbit scl=P2^2; void delay(void) { _nop_( ...… 查看全部问答> |




