home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / cpm / utils / asmutl / asmlib.lbr / MULDH.AZM / MULDH.ASM
Encoding:
Assembly Source File  |  1991-06-25  |  1.4 KB  |  61 lines

  1. ;----------------------------------------------------------------
  2. ;        This is a module in the ASMLIB library
  3. ;
  4. ; The following is the multiplication routine.
  5. ; Multiplicand is in bc, multiplier in de , result is in dehl.
  6. ;
  7. ;            Written         R.C.H.     16/8/83
  8. ;            Last Update    R.C.H.       16/8/83
  9. ;----------------------------------------------------------------
  10. ;
  11.     name    'muldh'
  12. ;
  13.     public    muldh
  14.     maclib    z80
  15. ;
  16. muldh:
  17.     mov    a,e        ; load lowest order mult byte.
  18.     push    d        ; save high order byte
  19.     call    bmult        ; do a 1 byte multiply
  20.     xthl            ; save low order products
  21.     push    psw        ; save high ord. 1'st product
  22.     mov    a,h        ; load high order multiplier byte
  23.     call    bmult        ; do second byte multiply
  24.     mov    d,a        ; position high order product
  25.     pop    psw
  26.     add    h        ; update 3'rd byte of product
  27.     mov    e,a        ; put into e
  28.     jrnc    nc1        ; skip increment if no carry
  29.     inr    d
  30. nc1:
  31.     mov    h,l        ; relocate first product
  32.     mvi    l,0        ; clear
  33.     pop    b        ; low order 2 bytes of product
  34.     dad    b
  35.     rnc            ; done if no carry
  36.     inx    d
  37.     ret
  38. ;
  39. ;This routine multiplies a * bc --> a-hl
  40. ;
  41. bmult:
  42.     lxi    h,0
  43.     lxi    d,7        ; d = 0 , e = 7 which is a loop counter
  44.     add    a        ; get first multiplier bit
  45. loop2:
  46.     jrnc    zero        ; zero skip
  47.     dad    b
  48.     adc    d
  49. zero:
  50.     dad    h
  51.     adc    a
  52.     dcr    e        ; decrement loop counter
  53.     jrnz    loop2
  54.     rnc
  55.     dad    b
  56.     adc    d
  57.     ret
  58.     end
  59.  
  60.  
  61.