von Matthias Zizelmann - www.zizelmann.de
zurück

8 Bit x 8 Bit Integermultiplikation mit PIC16XXX Befehlssatz

Dieser Code ist mit der Entwicklungsumgebung MPLAB IDE 7.20 von Microchip geschriben.

        LIST P=16F57

MDUCOUNT   equ     0x18          ;Hilfszaehler bei der Division und Multiplikation
AL         equ     0x19
AH         equ     0x1A
BL         equ     0x1B          ;Divisor
BH         equ     0x1C


             org     0

               ;  ++++++++++++++++++++++++++++++++++++++++++++++++
               ;  + Unterprogramm : 8 Bit * 8 Bit                +
               ;  +                                              +
               ;  +   Parameter :                                +
               ;  +     AL : Multiplikator                       +
               ;  +     AH : Multiplikand                        +
               ;  +                                              +
               ;  +   Rueckgabe :                                +
               ;  +     BL : Ergebnis (LB)                       +
               ;  +     BH : Ergebnis (HB)                       +
               ;  ++++++++++++++++++++++++++++++++++++++++++++++++
mul88          clrf    BL
               clrf    BH
               movlw   8
               movwf   MDUCOUNT
               ;
               movf    AL,w         ;Lade Multiplikator in das Additionsregister w
               bcf     _C
               ;
loopmul        rrf     AH,f
               btfsc   _C           ;Ist das Bit = 1 ?
               addwf   BH,f         ;C = 1 ! BH = BH + W
               ;
               rrf     BH,f         ;16 Bit Ergebnisregister um 1 nach Rechts schieben.
               rrf     BL,f
               ;
               decfsz  MDUCOUNT,f   ;Sind bereits alle 8 Bits bearbeitet worden ?
               goto    loopmul
               retlw   0