英文:
Assembly functions and labels that are jumped to; is 8-BYTE alignment necessary or not?
问题
In assembly, it's not necessary for function labels or labels within functions to be aligned at an 8-BYTE boundary for jumps. Label alignment is typically not a requirement in assembly language programming. The code you provided in the first example is perfectly fine:
func:
jmp .ret1
.ret1:
mov eax, 1
ret
.ret2:
mov eax, 2
ret
There's no need to insert ALIGN directives in this context. Alignment requirements are often architecture-specific and can vary, but in general, they are not tied to labels within functions or functions themselves in most assembly languages.
英文:
I have a question about jumping in assembly. Is it necessary for a function label to be aligned at an 8-BYTE boundary when we want to jump to it?
For example:
func:
jmp .ret1
.ret1: mov eax, 1
ret
.ret2: mov eax, 2
ret
Here I have a function with 2 labels and I just jumped to the first one. Is it necessary for each label to be aligned at an 8-BYTE boundary?
Is the following necessary:
func:
jmp .ret1
ALIGN 8
.ret1: mov eax, 1
ret
ALIGN 8
.ret2: mov eax, 2
ret
What about functions? Each function must be aligned at an 8-BYTE boundary or is it not important?
答案1
得分: 3
没有这样的要求。然而,将函数入口点和其他跳转目标对齐到16字节可能会在代码不在µop缓存中时提高性能。但效果相对较小。如果有疑问,请进行基准测试。
英文:
There is no such requirement. However, aligning function entry points and other jump targets to 16 byte may improve performance when the code is not in the µop cache. The effect is fairly minor though. When in doubt, benchmark.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论