Rearranging Subroutine Labels

One thing you might want to do to make subroutines look neat is to rearrange the labels so that they are in order either numerically or alphabetically.

Example
The following routine multiplies two 32-bit numbers, and produces a 32-bit result: Multiply: ;============================================================================== ; INPUT:	d0 = Multiplicand 1 ("X") ;		d1 = Multiplicand 2 ("Y") ; OUTPUT:	d0 = Product ; REGISTERS:	d0 = INPUT: X ;		d1 = INPUT: Y ;		d2 = OUTPUT ;============================================================================== 	movem.l	d1-d2,-(a7)	; Save Registers. moveq	#0,d2 .2:	lsr.l	#1,d1 bcc.b	.1 add.l	d0,d2 .1:	add.l	d0,d0 tst.l	d1 bne.b	.2 move.l	d2,d0 movem.l	(a7)+,d1-d2	; Restore Registers. rts After label rearranging, it would look like this: Multiply: ;============================================================================== ; INPUT:	d0 = Multiplicand 1 ("X") ;		d1 = Multiplicand 2 ("Y") ; OUTPUT:	d0 = Product ; REGISTERS:	d0 = INPUT: X ;		d1 = INPUT: Y ;		d2 = OUTPUT ;============================================================================== 	movem.l	d1-d2,-(a7)	; Save Registers. moveq	#0,d2 .1:	lsr.l	#1,d1 bcc.b	.2 add.l	d0,d2 .2:	add.l	d0,d0 tst.l	d1 bne.b	.1 move.l	d2,d0 movem.l	(a7)+,d1-d2	; Restore Registers. rts In the above examples, "Multiply:" is a global label, and ".1:" and ".2:" are local labels. Note that the labels ".1" and ".2" were interchanged so that they are in numerical order.

Algorithm
To do label rearranging, follow these steps:
 * Gather all the local labels after the global label.
 * Assign the label ".1" to the first local label that appears after the global label, ".2" to the next local label after that, etc.