mul8.asm 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. __MUL8: ; Performs 8bit x 8bit multiplication
  2. ;PROC
  3. ;LOCAL __MUL8A
  4. ;LOCAL __MUL8LOOP
  5. ;LOCAL __MUL8B
  6. ; 1st operand (byte) in A, 2nd operand into the stack (AF)
  7. pla ;- pop hl ; return address
  8. sta z80_h
  9. pla
  10. sta z80_l
  11. tsx ;- ex (sp), hl ; CALLE convention
  12. lda $0103,x
  13. ldy z80_h
  14. sta z80_h
  15. tya
  16. sta $0103,x
  17. lda $0104,x
  18. ldy z80_l
  19. sta z80_l
  20. tya
  21. sta $104,x
  22. ;;__MUL8_FAST: ; __FASTCALL__ entry
  23. ;; ld e, a
  24. ;; ld d, 0
  25. ;; ld l, d
  26. ;; sla h
  27. ;; jr nc, __MUL8A
  28. ;; ld l, e
  29. ;;__MUL8A:
  30. ;; ld b, 7
  31. ;;__MUL8LOOP:
  32. ;; add hl, hl
  33. ;; jr nc, __MUL8B
  34. ;; add hl, de
  35. ;;__MUL8B:
  36. ;; djnz __MUL8LOOP
  37. ;; ld a, l ; result = A and HL (Truncate to lower 8 bits)
  38. __MUL8_FAST: ; __FASTCALL__ entry, a = a * h (8 bit mul) and Carry
  39. lda %8 ;- ld b,8
  40. sta z80_b
  41. lda z80_a ;- ld l,a
  42. sta z80_l
  43. eor z80_a ;- xor a
  44. __MUL8LOOP:
  45. clc ;- add a,a ; a *= 2
  46. adc z80_a
  47. asl z80_l ;- sla l
  48. jcs __MUL8B ;- jp nc, __MUL8B
  49. clc ;- add a,h
  50. adc z80_h
  51. __MUL8B:
  52. ;- djnz __MUL8LOOP
  53. rts ;- ret ; result = HL
  54. ;- ENDP