piclist 2001\03\13\130905a >
Thread: math calibration algorithm ?
face BY : Nikolai Golovchenko email (remove spam text)

Just thought that once we have only 15 bits in divisor, the routine
can be optimized quite a bit:

; Input:
;  a1:a0 - 10 bit dividend   (a0 - lower byte)
;  b1:b0 - 15 bit divisor in 7Q8 format (b1 is integer, b0 is
;          fractional)
; Output:
;  c1:c0 - 15 bit quotient in 7Q8 format
; Temporary:
;  count - counter

;left align the dividend
; (shift accumulator left 1 bit to get the first result bit weight
;  equal to 128)
       rlf     a0, f
       rlf     a1, f              ;carry is cleared here
;initialize registers
       movlw 15                   ;15 iterations
       movwf count
       clrf c0                    ;clear result - it will be used
       clrf c1                    ;to shift zeroes to dividend
       rlf c0, f                  ;shift in next result bit
       rlf c1, f
       rlf a0, f                  ;and shift out next bit of dividend
       rlf a1, f                  ;to remainder

       movf b0, w                 ;load w with lower divisor byte
       skpnc                      ;if remainder positive - subtract,
        goto div_add              ;if negative - add
       subwf a0, f
       movf b1, w
        incfsz b1, w
         subwf a1, f
       goto div_next
       addwf a0, f
       movf b1, w
        incfsz b1, w
         addwf a1, f
;here carry has a new result bit
       decfsz count, f
        goto div_loop
;shift in last result bit
       rlf c0, f
       rlf c1, f


http://www.piclist.com hint: PICList Posts must start with ONE topic:
[PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads

<19014758425.20010313200854@yahoo.com> 7bit

In reply to: <287967385.20010313181544@yahoo.com>
See also: www.piclist.com/techref/microchip/math/index.htm?key=math
Reply You must be a member of the piclist mailing list (not only a www.piclist.com member) to post to the piclist. This form requires JavaScript and a browser/email client that can handle form mailto: posts.
Subject (change) math calibration algorithm ?

month overview.

new search...