*------------------------------------------------------------------------------ * NAME STR_REVERSE *------------------------------------------------------------------------------ * DEPENDENCY None * PURPOSE Reverse the bytes in the string at (A1). * DESCRIPTION Reverses the bytes in the string whose address is passed in A1. * INPUTS : * A1.L = Address of the string to be reversed * OUTPUTS : * A1.L = Address of the string to be reversed (Preserved) *------------------------------------------------------------------------------ str_reverse move.l d0-d1/a1-a2,-(a7) ; Save working registers move.l a1,a2 ; Copy start address move.w (a1)+,d0 ; Fetch length word beq.s sr_quit ; Nothing to do adda.w d0,a2 ; Near the end of the string addq.l #1,a2 ; The last character in the string lsl.w #1,d0 ; D0 = INT(D0/2) OK for odd and even ! bra.s sr_next ; Skip the first one for DBRA sr_loop move.b (a2),d1 ; Fetch the 'last' character move.b (a1),(a2) ; Move the 'first' byte to 'last' move.b d1,(a1)+ ; Move the 'last' byte to 'first' subq.l #1,a2 ; And adjust 'last' sr_next dbra d0,sr_loop ; And do the rest sr_quit movem.l (a7)+,d0-d1/a1-a2 ; Restore the working registers rts