; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; <<<<<<< ParaPIC ERROR Found >>>>>>>> device SX28,STACKX, OPTIONX, CARRYX ;Fractional multiply. ;This is a routine that multiplies two values, ; one treated as an integer, ; and the other treated as a binary fraction. ;Adapted from 6800 code by Ira Chayut. ;BYTE Magazine, September 1976, Programming Quickies, page 124. org $10 arg1 Res 1 arg2 Res 1 RESET Start Start CLRF fsr ;test code: 255 * 2/3 ~= 170. Actually returns 166. MOVLW d'255' MOVWF arg1 MOVLW 256*2/3 MOVWF arg2 CALL fracmul2 ;test code: 80 * 1/2 ~= 40. Actually returns 40. MOVLW d'80' MOVWF arg1 MOVLW 256*1/2 MOVWF arg2 CALL fracmul2 GOTO $ fracmul ;This version depends on CARRYX being off. CLRW ;W=0 fracmul_mloop BCF status,c RRF arg1 ;ARG1:=ARG1/2 BCF status,c ; don't copy the carry RLF arg2 ;CY:=MSB(ARG2), ARG2:=ASL(ARG2,1) BTFSC status,c ;IF CY=0 THEN SKIP THE ADDITION ADDWF arg1,w ;ELSE W:=W+ARG1 ; CARRYX must be off. MOVF arg2 BTFSS status,z ;IF ARG2 NE 0 THEN REITERATE GOTO @_mloop RETLW 0h ;ELSE RETURN WITH RESULT IN W fracmul2 ;Version not sensitve to CARRRYX CLRW ;W=0 fracmul2_loop BCF status,c RRF arg1 ;arg1 = arg1 / 2 BCF status,c BTFSC arg2,d'7' ;if arg2 <= 128 ADDWF arg1,w ; W = W + arg1 BCF status,c RLF arg2 ;arg2 = arg2 * 2 MOVF arg2 ;if arg2 <> 0 BTFSS status,z ; goto loop GOTO @_loop RETLW 0h ;return end