# SXMicrocontrollerMathMethod

## Divide 8 bit int by 8 bit to 24 bit float (AN575)

```;***********************************************
;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*10-2+5+14*25-2+4+3 = 449 instruction
;       cycles worst case (including call and return)
;***********************************************
fdiv24_8_8
mov	W, BARGB0
snb	Z
retw	#1		;divide by zero
clr	AEXP
mov	W, AARGB0
snb	Z
retw	#0		;zero result
;loop to use all 8 bits of dividend (integer 8 by 8 divide)
mov	AARGB1, W
clr	BARGB1
mov	W, #\$08
mov	AARGB0, W		;aargb0 is used as loop counter
fdiv24_8_8b
rl	AARGB1
rl	BARGB1
mov	W, BARGB0
mov	W, BARGB1-w
snb	C
mov	BARGB1, W
decsz	AARGB0
jmp	fdiv24_8_8b
rl	AARGB1		;aargb1 is the integer quotient so far
;loop to fill all the bits of 16bit mantissa
clr	AARGB0
mov	W, #\$8E
mov	AEXP, W
clrb	C
fdiv24_8_8c
rl	BARGB1
mov	W, BARGB0
sb	C		;check carry (9th bit)
jmp	fdiv24_8_8d
sub	BARGB1, W
setb	C
jmp	fdiv24_8_8e
fdiv24_8_8d
mov	W, BARGB1-w
snb	C
mov	BARGB1, W
fdiv24_8_8e
rl	AARGB1
rl	AARGB0
dec	AEXP
sb	AARGB0.7
jmp	fdiv24_8_8c
clrb	AARGB0.7		;replace explicit msb with sign
retw	#0
;***********************************************

; Nikolai http://techref.massmind.org/member/NG--944

```

 file: /Techref/scenix/lib/math/div/8by8to24fp-ng_sx.htm, 2KB, , updated: 2004/6/10 14:40, local time: 2020/9/29 19:59, owner: NG--944, TOP NEW HELP FIND:  3.237.71.23:LOG IN

 ©2020 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?Please DO link to this page! Digg it! / MAKE! SX Microcontroller Math Method - Divide 8 bit int by 8 bit to 24 bit float (AN575)

After you find an appropriate page, you are invited to your to this massmind site! (posts will be visible only to you before review) Just type in the box and press the Post button. (HTML welcomed, but not the <A tag: Instead, use the link box to link to another page. A tutorial is available Members can login to post directly, become page editors, and be credited for their posts.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

### Welcome to sxlist.com!

Site supported by
& kind contributors
just like you!

(here's why

Copies of the site on CD
are available at minimal cost.

.