Heyo,
My class at college has us writing programs in assembly. I have never truly appreciated the ease of C until now.
Now, when I program in assembly, I often have to make while/for/if loops and conditionals with labels eg:
SKIP:
...
COMP:ADD R1, R1, #0 ;Check for equality
BRZ WHILEEND
... ;code inside the while loop
JMP COMP ;Return to while loop
WHILEEND:
...
So, in this while loop (example) I have used 1 label for the subroutine and 2 more for the loop itself. I've run out of good label names for all the loops and branches I'm doing in assembly, what do you guys do to keep it varied and descriptive?
In a lot of assemblers you can make multiple labels with the same (usually numeric) name. That feature lets you reuse labels for your loops, using jmp 1f
to jump forward to the nearest label 1
or jmp 1b
to jump backward to the nearest label 1
.
Most assemblers allow local labels:
routine_1:
...
.loop:
...
jne .loop
routine_2:
...
.loop:
...
jne .loop
...
jmp routine_1.loop
or anonymous labels where you can reuse the same label name and reference "closest backward" or "closest forward":
routine_1:
...
@@:
...
jne @b
routine_2:
...
@@:
...
jne @b
(b for backwards)
If neither is supported in your assembler, I suppose you could prefix all local labels with the label of the routine in question:
routine_1:
...
routine_1.loop:
...
jne routine_1.loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With