please dont rip this site

PIC Microcontoller Math Method

(8 bits * 256) / 8 bits

from by Nikolai Golovchenko


; 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

        clrf temp               ;prepare temp regs
        clrf temp+1
        clrf temp+2
        clrf x+1
        bsf temp, 0             ;set counter bit
        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
         subwf temp+2, f
        goto div8scaled8_next

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

        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!

See also:

file: /Techref/microchip/math/8bmul256div8b-ng.htm, 1KB, , updated: 2000/12/8 12:18, local time: 2021/4/15 03:08,

 ©2021 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 - (8 bits * 256) / 8 bits </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 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 2021 contributors:
o List host: MIT, Site host, Top posters @20210415 Harold Hallikainen, RussellMc, Neil, Bob Blick, Alan Pearce, Spehro Pefhany, Clint Jay, Jason White, Richard Prosser, Alexandre Guimaraes,
* 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!