ON 20080610@10:24:29 AM at page: http://www.piclist.com/microchip/math/div/24by16ad.htm#39609.3844907407 James Newton[JMN-EFP-786] published post 39609.3844907407 tecnico@innotec.it asks:
I have tried to modify and use the code for a PIC 18F2480 (16 bit) but I can't get it to work, even with the modify of mr. jaakko-haakana. This is what I got: DIV24_16u: movlw d'24' ; for 24 shifts movwf R5Hi ; clrf REMBH ; clear remainder. clrf REMBL ; d2416lp: rlcf DATO1L,f ; build up remainder. rlcf DATO1H,f ; rlcf DATO1U,f ; rlcf REMBL,f ; rlcf REMBH,f ; ; remainder is 16-bit, but may have spilled over into carry. btfss STATUS,C ; check for remainder spill into carry. goto d2416s ; movf DATO2L,W ; subwfb REMBL,f ; Carry bit is the 17th bit of this subtract! movf DATO2H,W ; subwfb REMBH,f ; bsf STATUS,C ; bit is known to be zero here. goto d2416ns ; d2416s: movf DATO2H,W ; divisor hi subwf REMBH,w ; remainder hi (w = remainder - divisor) btfss STATUS, C goto d2416ns ; (remainder < divisor), shift in a '0' movf DATO2L,W subwf REMBL,w btfss STATUS,C goto d2416ns ; (remainder < divisor), shift in a '0' movf DATO2L,W ; The remainder is larger, so subtract subwf REMBL,f ; ... divisor FROM the remainder and movf DATO2H,W ; ... shift a '1' into the quot. subwfb REMBH,f ; d2416ns: decfsz R5Hi,f ; check all bits goto d2416lp ; rlcf DATO1L,f ; shift in final quotient bit. rlcf DATO1H,f ; rlcf DATO1U,f ; return Can anybody advise me about where is the error? Thanks in advance. Lorenzo. Email: tecnico at innotec.it|Delete 'P-' before: '' but after: '