;***********************************************
;Floating point division of two unsigned integer
;8 bit variables
;
;Input: AARGB0 - dividend (nominator)
; BARGB0 - divisor (denominator)
;Output:
; AEXP, AARGB0, AARGB1 - quotient
; (MICROCHIP format - AN575)
; w = 0 on success
; w = 1 error: divide by zero
;Temporaries:
; BARGB1
;
;RAM - 5 bytes
;ROM - 41 words
;Speed - 7 + 4 + 8 * 9 + 4 + 14 * 23 + 4 = 413 instruction
; cycles worst case (including call and return)
;***********************************************
fdiv24_8_8
movfw BARGB0
skpnz
retlw 1 ;divide by zero
clrf AEXP
movfw AARGB0
skpnz
retlw 0 ;zero result
;loop to use all 8 bits of dividend (integer 8 by 8 divide)
movwf AARGB1
clrf BARGB1
movlw 0x08
movwf AARGB0 ;aargb0 is used as loop counter
fdiv24_8_8b
rlf AARGB1, f
rlf BARGB1, f
movfw BARGB0
subwf BARGB1, w
skpnc
movwf BARGB1
decfsz AARGB0, f
goto fdiv24_8_8b
rlf AARGB1, f ;aargb1 is the integer quotient so far
;loop to fill all the bits of 16bit mantissa
clrf AARGB0
movlw 0x8E
movwf AEXP
clrc
fdiv24_8_8c
rlf BARGB1, f
movfw BARGB0
skpc ;check carry (9th bit)
goto fdiv24_8_8d
subwf BARGB1, f
setc
goto fdiv24_8_8e
fdiv24_8_8d
subwf BARGB1, w
skpnc
movwf BARGB1
fdiv24_8_8e
rlf AARGB1, f
rlf AARGB0, f
decf AEXP, f
btfss AARGB0, 7
goto fdiv24_8_8c
bcf AARGB0, 7 ;replace explicit msb with sign
retlw 0
;***********************************************
Nikolai
http://techref.massmind.org/member/NG--944
| file: /Techref/microchip/math/div/8by8to24fp-ng.htm, 2KB, , updated: 2000/4/10 11:06, local time: 2025/10/23 17:45,
216.73.216.20,10-1-5-169:LOG IN
|
| ©2025 These pages are served without commercial sponsorship. (No popup ads, etc...).Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE. Questions? <A HREF="http://www.ecomorder.com/techref/microchip/math/div/8by8to24fp-ng.htm"> PIC Microcontoller Math Method </A> |
| Did you find what you needed? |
Welcome to ecomorder.com! |
|
Ashley Roll has put together a really nice little unit here. Leave off the MAX232 and keep these handy for the few times you need true RS232! |
.