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 / Z80ASM24.ZIP / TEST2.ASM < prev    next >
Assembly Source File  |  1991-10-06  |  1KB  |  41 lines

  1. mult:                ; unsigned sixteen bit integer multiply.
  2. ;
  3. ; on entrance:    multiplier in de.
  4. ;        multiplicand in hl.
  5. ;
  6. ; on exit: result in hl.
  7. ;
  8. ; register uses:
  9. ;
  10. ;
  11. ;    h    high order partial result
  12. ;    l    low order partial result
  13. ;    d    high order multiplicand
  14. ;    e    low order multiplicand
  15. ;    b    counter for number of shifts
  16. ;    c    high order bits of multiplier
  17. ;    a    low order bits of multiplier
  18. ;
  19.     ld    b,16        ; number of bits- initialize
  20.     ld    c,d        ; move multiplier
  21.     ld    a,e        ;
  22.     ld    x,y        ; should get 'u' error
  23.     load    a,b        ; should get 'o' error
  24.     cp    'A'        ; test 'x' format
  25.     ex    de,hl        ; move multiplicand
  26.     ld    hl,0        ; clear partial result
  27.     eject            ; test eject processing
  28. ;
  29. mloop:    srl    c        ; shift multiplier right
  30.     rra            ; least significant bit is in carry
  31.     jr    nc,noadd-$    ; if no carry skip the add
  32.     add    hl,de        ; else add multiplicand to partial result
  33. ;
  34. noadd:    ex    de,hl        ; shift multiplicand left
  35.     add    hl,hl        ; by multiplying it by two
  36.     ex    de,hl
  37.     djnz    mloop-$        ; repeat until no more bits
  38.     ret
  39. ;
  40.     end
  41.