问题描述
目前,我正在阅读关于Raspberry Pi OS开发的,并对本地标签的使用方式感到疑惑在这段代码片段(GCC ARM Assembly)中使用:
...
b 2f
1:
stmia r4!,{r5-r8}
2:
cmp r4,r9
blo 1b
...
如果您使用 1:
作为标签,您必须指定 f
或 b
,以使汇编程序知道跳转的目标方向。据我所知,你也可以使用这个:
...
b .2
.1 :
stmia r4!,{r5-r8}
.2:
cmp r4,r9
blo .1
...
我认为这个选项不太令人困惑(本地标签在x86程序集中也用点标记),因为没有额外的标签参考后的字母。我测试了生成的机器码,它是一样的。所以我的问题:
-
为什么你会使用其中一种变体?
-
为什么需要用
f
或b
来指定跳转的方向, ? 无需担心,这就是为什么你也需要指定方向。你可以跳到前面或后面的一个,但不能超过他们。
1:foo
...
1:bar
...
jmp 1b#跳转到栏
...
jmp 1f#跳转到baz
...
1:baz
...
1:qux
...
jmp 1b#跳转到qux
只要您仅在一个区块内使用它们,您就可以确定它们将按预期工作,而不会与其他任何内容发生冲突。
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
...
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
...
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?
Why is it necessary to specify the direction of the jump with either
f
orb
?
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程序集本地标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!