This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

16-BIT 16-BIT BY 16-BIT MULTIPLICATION ROUTINE

I am trying to understand this routine to see what it actually does.

Appreciate if anybody care to explain.

;***********************************************************************************
; THIS IS A 16-BIT BY 16-BIT MULTIPLICATION ROUTINE
; THE RESULT IS A 32-BITS LONG
; MULTIPLICAND X MULTIPLIER = RESULT


MULER1  EQU 0288H  ;MULTIPLIER, LBYTE
MULER2  EQU MULER1+1 ;MULTIPLIER, HBYTE

MULND1  EQU 028AH
MULND2  EQU MULND1+1 ;MULTIPLICAND, LWORD
MULND3  EQU MULND1+2
MULND4  EQU MULND1+3 ;MULTIPLICAND, HWORD

MULRT1  EQU 0298H
MULRT2  EQU MULRT1+1  ;MULTIPLICATION RESULT, LWORD
MULRT3  EQU MULRT1+2
MULRT4  EQU MULRT1+3  ;MULTIPLICATION RESULT, HWORD

MULT16
 CLR &MULRT1  ;CLEAR MULTIPLICATION RESULT LOCATION, LWORD
 CLR &MULRT3  ;CLEAR MULTIPLICATION RESULT LOCATION, HWORD
 CLR &MULND3  ;CLEAR MULTIPLICAND LOCATION, HWORD
 MOV #020h,R15  ;SET COUNTER
MULT_XBIT
 CLRC
 RRC &MULER1
 JNC MULT_SHIFT 
MULT_ADD
 ADD &MULND1,&MULRT1 ;ADD MULTIPLICAND WITH RESULT
  ADDC &MULND3,&MULRT3 ;ADD MULTIPLICAND WITH RESULT
MULT_SHIFT
 RLA &MULND1  ;SHIFT LEFT MULTIPLICAND, LWORD
 RLC &MULND3  ;SHIFT LEFT MULTIPLICAND, HWORD
 DEC R15
 JNZ MULT_XBIT
 RET

  • It is an assemble code routine that multiplies two 16-bit unsigned integers to produce a 32-bit unsigned result.

    Multiplier is given in RAM locations 0x0288 and 0x0289. Multiplicand is given in RAM locations 0x028A and 0x028B.

    This routine uses R15 to count the number of shifts, which is 32 (i.e., 0x0020); and uses shift, test, and add/no_add do the multiplication and store the result in RAM locations 0x0298-0x029B. Original contends of RAM locations 0x0288-0x028D are destroyed.

    The hardware multiplier is not used.

    There is no simple c-code equivalent for this.

**Attention** This is a public forum