Oh! It wasn't as hard as I thought it would be.
And yup, it's trying to pull the parameters off the stack, and would be overwriting the variables with random values from RAM.
I assume you've set those variables before calling the routine.
Commenting these should help...
Code:
; Set up the stack
; movff FSR2L, POSTINC1
; movff FSR1L, FSR2L
; Initialize _ang to passed parameter
; movlw 0xfd
; movff PLUSW2, _ang
; movlw 0xfe
; movff PLUSW2, _ang+1<hr>; Calculates the magnitude and direction of the given ordered pair
atan2_sqrt:
; Set up the stack
; movff FSR2L, POSTINC1
; movff FSR1L, FSR2L
; Initialize _x to passed parameter
; movlw 0xfb
; movff PLUSW2, _x
; movlw 0xfc
; movff PLUSW2, _x+1
; movff POSTINC2, _x
; movff POSTDEC2, _x+1
; Initialize _y to passed parameter
; movlw 0xfd
; movff PLUSW2, _y
; movlw 0xfe
; movff PLUSW2, _y+1
; movlw 0x03
; movff PLUSW2, _y+1
; movlw 0x02
; movff PLUSW2, _y
ADDED: OOPs, missed a couple ...
Code:
; Restore the stack to its previous state
; movf POSTDEC1
; movff INDF1, FSR2L
and there's another banksel atans in the as_loop_start: part.
Bookmarks