'align' instruction on MIPS

泄露秘密 提交于 2019-12-04 11:26:49

问题


What exactly does this instruction do? I know that it tries to align data with a multiple of a specific number but why would you need to do this? Is there an equivalent instruction in other assemblers?


回答1:


You usually align data to get better performance. For most processors, memory access has some penalty when not accessing specific byte boundaries. For other assemblers, there often is some kind of pseudo-op .align for this. Most compilers also align their data structures (though you can disable it for debug purposes).

Also See this Wikipedia entry.

Note that non-emulated MIPS systems might even crash if you try to access unaligned memory cells (see here and here).




回答2:


Is there an equivalent instruccion in other assemblers?

MASM has an Align directive: http://msdn.microsoft.com/en-us/library/dwa9fwef(VS.80).aspx




回答3:


It aligns everything to the nth power of two. Its not an instruction, its a directive that will be translated into instructions

As for its usage,for exampe:

mips32 instructions are always 32 bits long. So each instruction should start on a word boundary. Adding an .align directive before the code starts, aligns things to 32 bits. This has many benefits, including that it only takes 1 memory access for the instruction´s fetch, and that it will probably be benefitial on the instruction cache.



来源:https://stackoverflow.com/questions/1021068/align-instruction-on-mips

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!