please dont rip this site

PIC Microcontoller Math Method


(8 bits * 256) / 8 bits

from by Nikolai Golovchenko

        cblock
        x:2
        y
        temp:3
        endc

; x = 256*x/y
;
; Input:
;  x - 8 bit unsigned integer
;  y - 8 bit unsigned integer (unmodified)
; Output:
;  x, x+1 - 16 bit unsigned integer (x - LSB, x+1 - MSB)
; Temporary:
;  temp, x+1 - current result/counter
;  temp+1, temp+2 - current remainder

div8scaled8
        clrf temp               ;prepare temp regs
        clrf temp+1
        clrf temp+2
        clrf x+1
        bsf temp, 0             ;set counter bit
        clrc
div8scaled8_loop
        rlf x, f                ;shift in zero and shift out next divisor bit
        rlf temp+1, f
        rlf temp+2, f

        movf y, w               ;move y to w
        btfss temp, 0
         goto div8scaled8_add
        subwf temp+1, f
        movlw 1
        skpc
         subwf temp+2, f
        goto div8scaled8_next

div8scaled8_add
        addwf temp+1, f
        movlw 1
        skpnc
         addwf temp+2, f

div8scaled8_next
        rlf temp, f             ;shift in next result
        rlf x+1, f
        skpc                    ;repeat until carry is set
         goto div8scaled8_loop

        movf temp, w            ;move result to x
        movwf x
        return                  ;done!


file: /Techref/microchip/math/8bmul256div8b-ng.htm, 1KB, , updated: 2000/12/8 12:18, local time: 2010/7/30 10:23,
TOP NEW HELP FIND: 
38.107.191.113:LOG IN
©2010 PLEASE DON'T RIP! DO: LINK / DIGG! / MAKE!

 ©2010 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!
<A HREF="http://www.piclist.org/techref/microchip/math/8bmul256div8b-ng.htm"> PIC Microcontoller Math Method - (8 bits * 256) / 8 bits </A>

Did you find what you needed?

 
FREE PCBs!
Enter the PICList design contest to win a free PCB from olimex.com!
  'What can I do?' - SiCKO

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

  .