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?
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.