PICMicrocontollerMathMethod

48 by 24 bit division by Andy Lee

Hi

I've made very good use of the code posted on your site so I'd like to give my thanks to the many contributers from whome I have learnt loads and who have save me a lot of time and head-scratching.

By way of thanks, I offer the following adaptation of Tony Nixons 24x24 bit division routine. I have expanded it to perform 48x24 bit division. While a little lardier than Nikolai Golovchenko's routine, it uses big-ended format (my preference) and provides a remainder (unfortunetly at the cost of a bit more ram). Anyway, I hope this may save someone a bit of time, as mine has been. Thanks all.

Code:

• allee at fastmail.co.uk shares this code:
;**************************************************************************
;Div4824U
;Inputs:
;	Dividend - Dividend:6	(0 - least significant!)
;	Divisor	 - Test:3	(0 - least significant!)
;Temporary:
;	Counter	 - Count
;	Shift	 - Shift:6
;Output:
;	Quotient - Dividend:6	(0 - least significant!)
;	Remainder- Rem:3	(0 - least significant!)
;
;Adaptation of 24x24 division by Tony Nixon with corrections
;by Frank Finster 3/15/2005.
;01-Sep-2006    Original version
;**************************************************************************

Div4824U:
;---------------------------------------------------
; SUBROUTINE - 48 by 24 BIT DIVISION
movlw 48
movwf Count
movff Dividend+0, Shift+0
movff Dividend+1, Shift+1
movff Dividend+2, Shift+2
movff Dividend+3, Shift+3
movff Dividend+4, Shift+4
movff Dividend+5, Shift+5
clrf Dividend+0
clrf Dividend+1
clrf Dividend+2
clrf Dividend+3
clrf Dividend+4
clrf Dividend+5

clrf Rem+2
clrf Rem+1
clrf Rem+0
dloop
bcf STATUS, C
rlcf Shift+0
rlcf Shift+1
rlcf Shift+2
rlcf Shift+3
rlcf Shift+4
rlcf Shift+5
rlcf Rem+0
rlcf Rem+1
rlcf Rem+2
movf Test+2, w
subwf Rem+2, w
btfss STATUS, Z
bra nochk

movf Test+1,w
subwf Rem+1,w
btfss STATUS, Z
bra nochk

movf Test+0,w
subwf Rem+0,w
nochk
btfss STATUS, C
bra nogo

movf Test+0,w
subwf Rem+0
btfsc STATUS, C
bra	nodec_remainM
decf Rem+1, f
movf Rem+1, w
xorlw 0xff
btfsc STATUS, Z
decf Rem+2, f
nodec_remainM
movf Test+1, w
subwf Rem+1, f
btfss STATUS, C
decf Rem+2, f
movf Test+2, w
subwf Rem+2, f
bsf STATUS, C
nogo
rlcf Dividend+0
rlcf Dividend+1
rlcf Dividend+2
rlcf Dividend+3
rlcf Dividend+4
rlcf Dividend+5
decfsz Count, f
goto dloop
return

• hahaha make sure when you set Count, that 48 is in DECIMAL!!
...:( wasted so much time because the compiler defaulted to hex!+
I've provided a version of this code that fixes an overflow error, illustrated by
0x34631A9FC / 0xDD39E9. Also, the code is provided for PIC12/PIC16 assembly. Thanks so much for the original work! See
http://www.piclist.com/techref/member/LPL-AEA-Z85/index.htm
+

 file: /Techref/microchip/math/div/48by24al.htm, 3KB, , updated: 2009/5/1 12:19, local time: 2022/1/25 20:48, TOP NEW HELP FIND:  52.203.18.65:LOG IN

 ©2022 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! PIC Microcontoller Math Method 48 by 24 bit division by Andy Lee

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 a nice message (short messages are blocked as spam) 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.

Attn spammers: All posts are reviewed before being made visible to anyone other than the poster.
 Did you find what you needed? "No. I'm looking for: " "No. Take me to the search page." "No. Take me to the top so I can drill down by catagory" "No. I'm willing to pay for help, please refer me to a qualified consultant" "No. But I'm interested. me at when this page is expanded."

 PICList 2022 contributors: o List host: MIT, Site host massmind.org, Top posters @20220125 * 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.

.