; ; *************************************************************************** ; *** Bubble Software Parallax to PIC Source Converter. Copyright 1999. *** ; *** http://www.picnpoke.com email: sales@picnpoke.com *** ; *************************************************************************** ; ; MULTIPLY multiplier, multiplicand ; Multiply two 16-bit numbers into a 16-bit product, permitting overflow. ; Device data and reset vector P = pic16c55 #include <16c55.inc> ; processor assembler definitions _CONFIG _xt_osc & _wdt_off & _protect_off reset start org 8 mulcH Res d'1' ; MSB of multiplicand. mulcL Res d'1' ; LSB of multiplicand. mulpH Res d'1' ; MSB of multiplier. mulpL Res d'1' ; LSB of multiplier. prodH Res d'1' ; MSB of product. prodL Res d'1' ; LSB of product. index Res d'1' ; temporary counter org 0 start MOVLW d'0' ; Outputs for LEDs to TRIS 6h MOVLW d'0' ; display 16-bit result. TRIS 7h MOVLW d'0' ; Problem: multiply MOVWF mulcH MOVLW 0x0B ; 0Bh by 1016h MOVWF mulcL MOVLW 0x10 MOVWF mulpH MOVLW 0x16 MOVWF mulpL CALL multiply MOVF prodL,w ; Show result in binary on MOVWF 6h MOVF prodH,w ; LEDs connected to ports. MOVWF 7h GOTO $ ; Endless loop Multiply CLRF prodH ; Clear product to make CLRF prodL ; way for new calculation. MOVLW d'16' ; Number of bits to calc. MOVWF index Multiply_loop BCF status,c RLF prodL ; Shift product left. RLF prodH BCF status,c RLF mulcL ; Shift multiplicand left. RLF mulcH BTFSS status,c ; If carry, add multiplier GOTO Multiply_skip MOVF mulpL,w ; to the product. Else skip. ADDWF prodL BTFSC status,c ; 16-bit addition: prod+mulp INCF prodH MOVF mulpH,w ADDWF prodH Multiply_skip DECFSZ index GOTO Multiply_loop RETLW 0h end