• Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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
 

TheAnimus

New Member
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.

Latest threads

EE World Online Articles

Loading
Top