division algorithm

Status
Not open for further replies.

finst

New Member
anyone can help me

i need 8bit and 16bit division algorithm and program code for pic microcontroller

thanks
 
Easy think shift instructions.

When you use a RRF (Rotate Right File) the extra bit is deumped in the carry.
ie:
Code:
div2 macro upperbyte, lowerbyte
RRF  upperbyte,F
RRF lowerbyte,F
endm
; This macro will divide the two params by 2.
; so you could div by 8, by calling that 4 times,
div8 macro upperbyte, lowerbyte
div2 upperbyte, lowerbyte
div2 upperbyte, lowerbyte
div2 upperbyte, lowerbyte
div2 upperbyte, lowerbyte
endm
; And once again to get a div by 16, call div 8 twice
div16 macro upperbyte, lowerbyte
div8 upperbyte, lowerbyte
div8 upperbyte, lowerbyte
endm

Of course this is a bit ugly, you should probably save program space by using a loop (DECFSZ or somthing)
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…