All about PIC microcontrollers
Within these pages, you can find many useful pieces of code mostly in assembly for the Microchip PIC micro controller family. A lot of people have spend many hours trying to put the bits and bytes together. If the code is NOT written by a member of the PCB Heaven community, then a link will be added above the code with the original website that this code was found.
Because the code is copied to our servers, you should know that:
The responsible web master of the website that the code is taken, has been informed and he has agreed to copy the code
All emails from the above contact have been kept as records but due to personal privacy cannot be shown in public.
The author of the code is always clearly indicated above the code. In some cases the author is unknown. If you happen to be the author of the code or you know the person who wrote it, please inform us by email and it will be added ASAP.
We would personally like to send the credits to all the people that managed to write some very interesting code and publish it, and special thanx to the people that originally hosted those code snippets and gave us the permission to copy them.
;*******************************************************************
; Double Precision Multiplication
;
; ( Optimized for Speed : straight Line Code )
;
;*******************************************************************;
; Multiplication : ACCb(16 bits) * ACCa(16 bits) -> ACCb,ACCc (
32
bits )
; (a) Load the 1st operand in location ACCaLO & ACCaHI ( 16
bits )
; (b) Load the 2nd operand in location ACCbLO & ACCbHI ( 16
bits )
; (c) CALL D_mpy
; (d) The 32 bit result is in location (
ACCbHI,ACCbLO,ACCcHI,ACCcLO )
;
; Performance :
; Program Memory : 240
; Clock Cycles : 233 (282)
;
; Note : The above timing is the worst case timing, when the
; register ACCb = FFFF. The speed may be improved if
; the register ACCb contains a number ( out of the
two
; numbers ) with less number of 1s.
;
; The performance specs are for Unsigned arithmetic (
i.e,
; with "SIGNED equ FALSE ").
;
; Program: DBL_MPYF.ASM
; Revision Date:
; 1-13-97 Compatibility with MPASMWIN
1.40
;
;*******************************************************************
SIGNED equ FALSE ; Set This To 'TRUE' if the
routines
; ; for Multiplication & Division
needs
; ; to be assembled as Signed Integer
; ; Routines. If 'FALSE' the above
two
; ; routines ( D_mpy & D_div ) use
; ; unsigned arithmetic.
;*******************************************************************
; multiplication macro
;
mulMac MACRO
LOCAL NO_ADD
;
rrf ACCdHI, F ;rotate d right
rrf ACCdLO, F
btfss STATUS,C ;need to add?
goto NO_ADD ; no addition necessary
movf ACCaLO,W ; Addition ( ACCb + ACCa -> ACCb )
addwf ACCbLO, F ;add lsb
btfsc STATUS,C ;add in carry
incf ACCbHI, F
movf ACCaHI,W
addwf ACCbHI, F ;add msb
NO_ADD rrf ACCbHI, F
rrf ACCbLO, F
rrf ACCcHI, F
rrf ACCcLO, F
;
ENDM
;
;*******************************************************************;
; Double Precision Multiply ( 16x16 -> 32 )
; ( ACCb*ACCa -> ACCb,ACCc ) : 32 bit output with high word
; in ACCb ( ACCbHI,ACCbLO ) and low word in ACCc ( ACCcHI,ACCcLO
).
;
D_mpyF ;results in ACCb(16 msb's) and
ACCc(16
lsb's)
;
IF SIGNED
CALL S_SIGN
ENDIF
;
call setup
;
; use the mulMac macro 16 times
;
;----------------------
; inserted by RAVI PAILOOR
movlw .16
movwf loopctr
;----------------------
loop mulMac
;----------------------
; inserted by RAVI PAILOOR