ARM 程序集本地标签 [英] ARM Assembly Local Labels
问题描述
我目前正在阅读有关 Raspberry Pi OS 开发的教程,并想知道本地标签的方式用于此代码片段(GCC ARM 程序集):
I'm currently reading a tutorial on Raspberry Pi OS development and was wondering about the way local labels are used in this code snippet (GCC ARM Assembly):
...
b 2f
1:
stmia r4!, {r5-r8}
2:
cmp r4, r9
blo 1b
...
如果使用 1:
作为标签,则必须在跳转指令后指定 f
或 b
以使汇编程序知道跳跃的目标方向.据我所知,你也可以使用这个:
If you use 1:
as a label you have to specify either f
or b
after the jump instruction to make the assembler know in which direction the jump is aimed. As far as I know you could also use this:
...
b .2
.1:
stmia r4!, {r5-r8}
.2:
cmp r4, r9
blo .1
...
我觉得这个选项少了很多混乱(本地标签在x86程序集中也是用点标记的),因为在标签引用后没有额外的字母.我已经测试了生成的机器代码,结果是一样的.所以我的问题:
I think this option is a lot less confusing (local labels are also marked with a dot in x86 assembly), because there is no additional letter after the label reference. I have tested the resulting machine code and it's the same. So my questions:
为什么要使用一种变体而不是另一种变体?
Why would you use the one variant over the other?
为什么需要用f
或b
来指定跳跃的方向?
Why is it necessary to specify the direction of the jump with either f
or b
?
推荐答案
重要的区别是编号的局部标签可以放心重复使用,这就是为什么您也需要指定方向.你可以跳到前面或后面的,但不能跳到后面的.
The important difference is that the numbered local labels can be reused without worry and that is why you need to specify the direction too. You can jump to preceding or following one, but not the ones beyond them.
1: foo
...
1: bar
...
jmp 1b # jumps to bar
...
jmp 1f # jumps to baz
...
1: baz
...
1: qux
...
jmp 1b # jumps to qux
只要您仅在单个块中使用它们,您就可以确定它们会按预期工作并且不会与其他任何内容发生冲突.
As long as you only use them within a single block only, you can be sure they will work as intended and not conflict with anything else.
这篇关于ARM 程序集本地标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!