home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / ENTERPRS / CPM / UTILS / S / ZCNFG21.LZH / CFGLIB.LZH / MPY16.Z80 < prev    next >
Text File  |  1992-11-03  |  896b  |  30 lines

  1.     public    mpy16
  2.  
  3. ; This routine multiplies the 16-bit values in DE and HL and returns the
  4. ; 32-bit result in HLBC (HL has high 16 bits; BC has low 16 bits).  Register
  5. ; pair AF is preserved.
  6.  
  7. mpy16:
  8.     ex    af,af'        ; Save AF
  9.     ld    a,h        ; Transfer factor in HL to A and C
  10.     ld    c,l
  11.     ld    hl,0        ; Initialize product
  12.     ld    b,16        ; Set bit counter
  13.     rra            ; Shift AC right so first multiplier bit
  14.     rr    c        ; ..is in carry flag
  15. mp161:
  16.     jr    nc,mp162     ; If carry not set, skip the addition
  17.     add    hl,de        ; Add multiplicand
  18. mp162:
  19.     rr    h        ; Rotate HL right, low bit into carry
  20.     rr    l
  21.     rra            ; Continue rotating through AC, with
  22.     rr    c        ; ..next multiplier bit moving into carry
  23.     djnz    mp161        ; Loop through 16 bits
  24.  
  25.     ld    b,a        ; Move A to B so result is in HLBC
  26.     ex    af,af'        ; Restore original AF registers
  27.     ret
  28.  
  29.     end
  30.