comparison src/math.asm @ 623:c40025d8e750

3.03 beta released
author heinrichsweikamp
date Mon, 03 Jun 2019 14:01:48 +0200
parents ca4556fb60b9
children cd58f7fc86db
comparison
equal deleted inserted replaced
622:02d1386429a6 623:c40025d8e750
1 ;============================================================================= 1 ;=============================================================================
2 ; 2 ;
3 ; File math.asm REFACTORED VERSION V2.99d 3 ; File math.asm combined next generation V3.03.2
4 ; 4 ;
5 ; Math subroutines 5 ; Math subroutines
6 ; 6 ;
7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved. 7 ; Copyright (c) 2011, JD Gascuel, HeinrichsWeikamp, all right reserved.
8 ;============================================================================= 8 ;=============================================================================
9 ; HISTORY 9 ; HISTORY
10 ; 2011-08-03 : [mH] moving from OSTC code 10 ; 2011-08-03 : [mH] moving from OSTC code
11 11
12 12
13 #include "hwos.inc" ; mandatory header 13 #include "hwos.inc" ; mandatory header
14 14
15 math CODE 15 math CODE
16 16
17 ;============================================================================= 17 ;=============================================================================
18 18
19 global convert_time ; converts hi:lo in minutes to hours (up:hi) and minutes (lo) 19 global convert_time ; converts hi:lo in minutes to hours (up:hi) and minutes (lo)
20 ; also usable for conversion of seconds to minutes and seconds 20 ; also usable for conversion of seconds to minutes and seconds
78 global subU16 ; sub_c:2 = sub_a:2 - sub_b:2 with UNSIGNED values 78 global subU16 ; sub_c:2 = sub_a:2 - sub_b:2 with UNSIGNED values
79 ; sets neg_flag if result is < 0 79 ; sets neg_flag if result is < 0
80 ; trashes WREG 80 ; trashes WREG
81 subU16: 81 subU16:
82 bcf neg_flag ; clear flag which will indicate if result is negative 82 bcf neg_flag ; clear flag which will indicate if result is negative
83 movf sub_b+0,W ; get Value to be subtracted, low byte 83 movf sub_b+0,W ; get value to be subtracted, low byte
84 subwf sub_a+0,W ; execute subtraction on low byte 84 subwf sub_a+0,W ; execute subtraction on low byte
85 movwf sub_c+0 ; copy result to output variable, low byte 85 movwf sub_c+0 ; copy result to output variable, low byte
86 movf sub_b+1,W ; get value to be subtracted, high byte 86 movf sub_b+1,W ; get value to be subtracted, high byte
87 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag 87 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag
88 movwf sub_c+1 ; copy result to output variable, high byte 88 movwf sub_c+1 ; copy result to output variable, high byte
89 btfsc STATUS,C ; borrow to propagate (B == /CARRY) ? 89 btfsc STATUS,C ; borrow to propagate (B == /CARRY) ?
90 return ; NO - result positive, done 90 return ; NO - result positive, done
91 bsf neg_flag ; YES - set flag 91 bsf neg_flag ; YES - set flag
92 comf sub_c+1 ; - do a 16 bit sign change 92 comf sub_c+1 ; - do a 16 bit sign change
93 negf sub_c+0 ; 93 negf sub_c+0 ; - ...
94 btfsc STATUS,C ; - carry to be propagated ? 94 btfsc STATUS,C ; - carry to be propagated ?
95 incf sub_c+1,F ; YES - do it 95 incf sub_c+1,F ; YES - do it
96 return ; - done 96 return ; - done
97
98
99 global cmpU16 ; sub_a:2 - sub_b:2 with UNSIGNED values
100 ; sets neg_flag if result is < 0, but does not store result itself
101 ; trashes WREG
102 cmpU16:
103 bcf neg_flag ; clear flag which will indicate if result is negative
104 movf sub_b+0,W ; get value to be subtracted, low byte
105 subwf sub_a+0,W ; execute subtraction on low byte
106 movf sub_b+1,W ; get value to be subtracted, high byte
107 subwfb sub_a+1,W ; execute subtraction on high byte, considering borrow flag
108 btfss STATUS,C ; borrow to propagate (B == /CARRY) ?
109 bsf neg_flag ; YES - result is negative, set flag
110 return ; done
97 111
98 112
99 global mult16x16 ; xC:4 = xA:2 * xB:2 with UNSIGNED values 113 global mult16x16 ; xC:4 = xA:2 * xB:2 with UNSIGNED values
100 ; trashes PRODL, PRODH, WREG 114 ; trashes PRODL, PRODH, WREG
101 mult16x16: 115 mult16x16:
249 clrf WREG 263 clrf WREG
250 addwfc isr_xC+3,F ; propagate carry 264 addwfc isr_xC+3,F ; propagate carry
251 return 265 return
252 266
253 267
254 global isr_signed_mult16x16 ; isr_xC = isr_xA * _isr_xB with SIGNED values 268 global isr_signed_mult16x16 ; isr_xC = isr_xA * isr_xB with SIGNED values
255 ; trashes PRODL, PRODH, WREG 269 ; trashes PRODL, PRODH, WREG
256 isr_signed_mult16x16: 270 isr_signed_mult16x16:
257 rcall isr_unsigned_mult16x16 ; do an unsigned multiplication first 271 rcall isr_unsigned_mult16x16 ; do an unsigned multiplication first
258 ; ; manage sign extension of operand B 272 ; ; manage sign extension of operand B
259 btfss isr_xB+1,7 ; is B negative ? 273 btfss isr_xB+1,7 ; is B negative ?