“对齐” MIPS指令
这个指令到底有什么作用? 我知道它会尝试将数据与特定数字的倍数对齐,但为什么需要这样做? 其他汇编器中是否有等效的指令?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您通常会对齐数据以获得更好的性能。 对于大多数处理器来说,当不访问特定字节边界时,内存访问会受到一些影响。 对于其他汇编程序,通常存在某种伪操作
.align
为此。 大多数编译器还会对齐其数据结构(尽管您可以出于调试目的禁用它)。另请参阅此维基百科条目。
请注意,如果您尝试访问未对齐的内存单元,非模拟 MIPS 系统甚至可能会崩溃(请参阅此处 和此处)。
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).
MASM 有一个对齐指令: http://msdn.microsoft .com/en-us/library/dwa9fwef(VS.80).aspx
MASM has an Align directive: http://msdn.microsoft.com/en-us/library/dwa9fwef(VS.80).aspx
它将所有内容对齐到 2 的 n 次方。 它不是一条指令,它是一个将被翻译成指令的指令
至于它的用法,例如:
mips32指令总是32位长。 因此每条指令都应该从字边界开始。 在代码开始之前添加 .align 指令,将内容对齐到 32 位。 这有很多好处,包括只需要 1 次内存访问来获取指令,并且它可能对指令缓存有利。
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.