Running out of label names in assembly
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 开发者_如何学Pythonout 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?
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
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
.
精彩评论