comparison 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
comparison
equal deleted inserted replaced
341:2144f19fa1eb 342:06299199dfb9
51 subwf sub_a+0, W ; Do the High Byte 51 subwf sub_a+0, W ; Do the High Byte
52 movwf sub_c+0 52 movwf sub_c+0
53 movf sub_b+1, W ; Get the Value to be Subbed 53 movf sub_b+1, W ; Get the Value to be Subbed
54 subwfb sub_a+1, W 54 subwfb sub_a+1, W
55 movwf sub_c+1 55 movwf sub_c+1
56
56 btfsc STATUS,C 57 btfsc STATUS,C
57 return ; result positve 58 return ; result positve
58 ; sub_c = sub_a - sub_b 59
59 bsf neg_flag ; result negative 60 bsf neg_flag ; result negative
60 movff sub_c+0,sub_b+0 61
61 movff sub_c+1,sub_b+1 62 comf sub_c+1 ; 16bit sign change.
62 setf sub_a 63 negf sub_c+0
63 setf sub_a+1 64 btfsc STATUS,C ; Carry to propagate ?
64 movf sub_b+0, W ; Get Value to be subtracted 65 incf sub_c+1,F ; YES: do it.
65 subwf sub_a+0, W ; Do the High Byte 66
66 movwf sub_c+0
67 movf sub_b+1, W ; Get the Value to be Subbed
68 subwfb sub_a+1, W
69 movwf sub_c+1
70 return 67 return
71
72 68
73 mult16x16: ;xA*xB=xC 69 mult16x16: ;xA*xB=xC
74 clrf xC+2 ; Clear the High-Order Bits 70 clrf xC+2 ; Clear the High-Order Bits
75 clrf xC+3 71 clrf xC+3
76 movf xA, w ; Do the "L" Multiplication first 72 movf xA, w ; Do the "L" Multiplication first