please dont rip this site

PIC Microcontoller Math Method

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

by Nikolai Golovchenko

;Floating point division of two unsigned integer
;8 bit variables
;Input: AARGB0 - dividend (nominator)
;       BARGB0 - divisor (denominator)
;       AEXP, AARGB0, AARGB1 - quotient
;       (MICROCHIP format - AN575)
;       w = 0 on success
;       w = 1 error: divide by zero
;       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)
        movfw BARGB0
         retlw 1                ;divide by zero
        clrf AEXP
        movfw AARGB0
         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
        rlf AARGB1, f
        rlf BARGB1, f
        movfw BARGB0
        subwf BARGB1, w
         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
        rlf BARGB1, f
        movfw BARGB0
        skpc                    ;check carry (9th bit)
         goto fdiv24_8_8d
        subwf BARGB1, f
        goto fdiv24_8_8e
        subwf BARGB1, w
         movwf BARGB1
        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


file: /Techref/microchip/math/div/8by8to24fp-ng.htm, 2KB, , updated: 2000/4/10 11:06, local time: 2024/7/23 23:02,

 ©2024 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!

<A HREF=""> PIC Microcontoller Math Method </A>

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 a nice message (short messages are blocked as spam) 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.

Link? Put it here: 
if you want a response, please enter your email address: 
Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
Did you find what you needed?

  PICList 2024 contributors:
o List host: MIT, Site host, Top posters @none found
- Page Editors: James Newton, David Cary, and YOU!
* Roman Black of Black Robotics donates from sales of Linistep stepper controller kits.
* Ashley Roll of Digital Nemesis donates from sales of RCL-1 RS232 to TTL converters.
* Monthly Subscribers: Gregg Rew. on-going support is MOST appreciated!
* Contributors: Richard Seriani, Sr.

Welcome to!