Electronic Projects, forums and more.

Go Back   Electronic Circuits Projects Diagrams Free > Electronics Categories > Micro Controllers


Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc.

Reply
 
LinkBack Thread Tools Display Modes
Old 19th December 2003, 04:50 AM   (permalink)
Default division algorithm

anyone can help me

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

thanks
finst is offline  
Old 19th December 2003, 08:06 PM   (permalink)
Default

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)
TheAnimus is offline  
Old 19th December 2003, 10:17 PM   (permalink)
Default Re: division algorithm

Quote:
Originally Posted by finst
anyone can help me

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

thanks
If you look on the PICLIST at http://www.piclist.com there are various maths routines you can download.
Nigel Goodwin is offline  
Old 20th December 2003, 12:39 AM   (permalink)
Default

hehehe it changed shift too bleep

sh!ft is a bad word !
TheAnimus is offline  
Reply

Bookmarks

Thread Tools
Display Modes





All times are GMT. The time now is 03:42 AM.


Electronic Circuits  |  Learning Electronics
Powered by vBulletin® Version 3.7.0
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.

eXTReMe Tracker