diff code_part1/OSTC_code_asm_part1/math.asm @ 342:06299199dfb9

Fix bad max depth value (fix sub16 to avoid trashing sub_b).
author JeanDo
date Fri, 20 May 2011 01:34:59 +0200
parents 8d6aca08f66b
children cec312042b94
line wrap: on
line diff
--- a/code_part1/OSTC_code_asm_part1/math.asm	Fri May 20 00:48:30 2011 +0200
+++ b/code_part1/OSTC_code_asm_part1/math.asm	Fri May 20 01:34:59 2011 +0200
@@ -53,23 +53,19 @@
 	movf   	sub_b+1, W              ; Get the Value to be Subbed
 	subwfb 	sub_a+1, W
 	movwf  	sub_c+1
+
 	btfsc	STATUS,C
 	return							; result positve
-;  sub_c = sub_a - sub_b
+
 	bsf		neg_flag				; result negative
-	movff	sub_c+0,sub_b+0
-	movff	sub_c+1,sub_b+1
-	setf	sub_a
-	setf	sub_a+1
-	movf   	sub_b+0, W             	;  Get Value to be subtracted
-	subwf  	sub_a+0, W             	;  Do the High Byte
-	movwf  	sub_c+0
-	movf   	sub_b+1, W               ;  Get the Value to be Subbed
-	subwfb  sub_a+1, W
-	movwf  	sub_c+1
+
+    comf    sub_c+1                 ; 16bit sign change.
+    negf    sub_c+0
+    btfsc   STATUS,C                ; Carry to propagate ?
+    incf    sub_c+1,F               ; YES: do it.
+
     return        
 
-
 mult16x16:		;xA*xB=xC
 	clrf    xC+2        	  ;  Clear the High-Order Bits
 	clrf    xC+3