Code:
+;************************************************************************** ;Div4824U ;Inputs: ; x - x:6 (x) (0 - least significant!) ; y - Test:3 (y) (0 - least significant!) ;Temporary: ; Counter - Count ; Shift - Shift:6 (mathint) ;Output: ; Quotient - x:6 (x) (0 - least significant!) ; Remainder- Rem:3 (0 - least significant!) ; ;Adaptation to PIC 12/16 Assembly and error fix of code by Frank Finster 3/15/2005 ;by Lewis Lineberger 4/24/2009 ;Fixes overrun in Rem+2 when upper bit of y+2 and Rem+2 are set, but Rem+2 is still ;less than y+2. Overrun is illustrated by 0x34631A9FC / 0xDD39E9. ;Adaptation of 24x24 division by Tony Nixon with corrections ;PIC18 assembly instructions in comments for easy adaptation. ;by Frank Finster 3/15/2005. ;Code adapted by Andy Lee ;01-Sep-2006 Original version ;************************************************************************** Div4824U ;--------------------------------------------------- ; SUBROUTINE - 48 by 24 BIT division movlw d'48' movwf Count ; movff x+0, Shift+0 movf x+0, W movwf mathint+0 ; movff x+1, Shift+1 movf x+1, W movwf mathint+1 ; movff x+2, Shift+2 movf x+2, W movwf mathint+2 ; movff x+3, Shift+3 movf x+3, W movwf mathint+3 ; movff x+4, Shift+4 movf x+4, W movwf mathint+4 ; movff x+5, Shift+5 movf x+5, W movwf mathint+5 clrf x+0 clrf x+1 clrf x+2 clrf x+3 clrf x+4 clrf x+5 clrf Rem+2 clrf Rem+1 clrf Rem+0 dloop bcf STATUS, C rlf mathint+0, F rlf mathint+1, F rlf mathint+2, F rlf mathint+3, F rlf mathint+4, F rlf mathint+5, F rlf Rem+0, F rlf Rem+1, F rlf Rem+2, F btfsc STATUS, C ; overrun goto subtract movf y+2, w subwf Rem+2, w btfss STATUS, Z goto nochk ;bra nochk movf y+1,w subwf Rem+1,w btfss STATUS, Z goto nochk ;bra nochk movf y+0,w subwf Rem+0,w nochk btfss STATUS, C ; Rem >= y goto nogo ;bra nogo subtract movf y+0,w subwf Rem+0, F btfsc STATUS, C goto nodec_remainM ;bra nodec_remainM decf Rem+1, f movf Rem+1, w xorlw 0xff btfsc STATUS, Z decf Rem+2, f nodec_remainM movf y+1, w subwf Rem+1, f btfss STATUS, C decf Rem+2, f movf y+2, w subwf Rem+2, f bsf STATUS, C nogo rlf x+0, F rlf x+1, F rlf x+2, F rlf x+3, F rlf x+4, F rlf x+5, F decfsz Count, f goto dloop return
file: /Techref/member/LPL-AEA-Z85/index.htm, 2KB, , updated: 2009/4/24 09:20, local time: 2024/12/27 19:34,
owner: LPL-AEA-Z85,
3.15.5.0: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://linistepper.com/techref/member/LPL-AEA-Z85/index.htm"> Member Homepage for LPL-AEA-Z85</A> |
Did you find what you needed? |