.section .data
msg1:
.asciz "Hello1: %d\r\n"
msg2:
.asciz "Hello2: %d\r\n"
.section .text
.global main
main:
mov r4, #0
.loop:
cmp r4, #5
bge .endloop
ldr r0, =msg1
mov r1, r4
bl printf
add r4, r4, #1
b .loop
.endloop:
mov r7, #1
mov r0, #0
swi 0
My assembly code runs on Raspberry Pi 4B, why is it that when I replace .loop: with loop: and .endloop: with endloop:, it still executes normally? What are the differences between .loop: and loop:? Thank you.
No difference, they're just label names.
.is a valid character in asm symbols, including as the first character.But by convention,
.labels are "local" to the function. In NASM syntax (an x86 assembler), they are actually scoped that way, so you can have.loopinside multiple different functions.In GNU Assembler (GAS) like here,
.loopisn't special at all; it would be an error (symbol redefinition) to havefoo:;.loop:earlier or later in the file..Lxyzlabels that start with a dot and capital L are special (not appearing in the symbol table of the.oat all even for debugging), but still file-scoped. https://sourceware.org/binutils/docs/as/Symbol-Names.html This is why GCC uses label names like.L0for branch targets within functions (if/else/loops/etc) and names like.LC0for constants in.rodata, and even stuff like.Lanchor0for locations it wants to mark to reference other stuff relative to.For actual local labels in GAS that you can define more than once, use bare numbers like
1:and refer to it with1bfor backwards to the nearest1in that direction,1ffor the nearest1:in the forward direction. Like1: bhi 1bis an infinite loop or not depending on the carry and zero flags.