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:
;************************************************************************** ;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. ;Code adapted by Andy Lee ;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
Comments:
Lewis Paul Lineberger of Alternate Energies Says:
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: 2024/11/15 03:30,
3.17.183.204:LOG IN
|
©2024 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? <A HREF="http://massmind.ecomorder.com/techref/microchip/math/div/48by24al.htm"> PIC Microcontoller Math Method 48 by 24 bit division by Andy Lee</A> |
Did you find what you needed? |
Welcome to ecomorder.com! |
Welcome to massmind.ecomorder.com! |
.