mul32.asm 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. #include once <_mul32.asm>
  2. ;
  3. __MUL32: ; multiplies 32 bit un/signed integer.
  4. ; First operand stored in DEHL, and 2nd onto stack
  5. ; Lowest part of 2nd operand on top of the stack
  6. ; returns the result in DE.HL
  7. lda z80_c ;- exx
  8. ldx z80_cp
  9. stx z80_c
  10. sta z80_cp
  11. lda z80_b
  12. ldx z80_bp
  13. stx z80_b
  14. sta z80_bp
  15. lda z80_e
  16. ldx z80_ep
  17. stx z80_e
  18. sta z80_ep
  19. lda z80_d
  20. ldx z80_dp
  21. stx z80_d
  22. sta z80_dp
  23. lda z80_l
  24. ldx z80_lp
  25. stx z80_l
  26. sta z80_lp
  27. lda z80_h
  28. ldx z80_hp
  29. stx z80_h
  30. sta z80_hp
  31. pla ;- pop hl ; Return ADDRESS
  32. sta z80_h
  33. pla
  34. sta z80_l
  35. pla ;- pop de ; Low part
  36. sta z80_d
  37. pla
  38. sta z80_e
  39. tsx ;- ex (sp),hl ; CALLEE -> HL = High part
  40. lda $0103,x
  41. ldy z80_h
  42. sta z80_h
  43. tya
  44. sta $0103,x
  45. lda $0104,x
  46. ldy z80_l
  47. sta z80_l
  48. tya
  49. sta $104,x
  50. lda z80_e ;- ex de,hl
  51. ldx z80_l
  52. stx z80_e
  53. sta z80_l
  54. lda z80_d
  55. ldx z80_h
  56. stx z80_d
  57. sta z80_h
  58. jsr __MUL32_64START ;- call __MUL32_64START
  59. __TO32BIT: ; Converts H'L'HLB'C'AC to DEHL (Discards H'L'HL)
  60. lda z80_c ;- exx
  61. ldx z80_cp
  62. stx z80_c
  63. sta z80_cp
  64. lda z80_b
  65. ldx z80_bp
  66. stx z80_b
  67. sta z80_bp
  68. lda z80_e
  69. ldx z80_ep
  70. stx z80_e
  71. sta z80_ep
  72. lda z80_d
  73. ldx z80_dp
  74. stx z80_d
  75. sta z80_dp
  76. lda z80_l
  77. ldx z80_lp
  78. stx z80_l
  79. sta z80_lp
  80. lda z80_h
  81. ldx z80_hp
  82. stx z80_h
  83. sta z80_hp
  84. lda z80_c ;- push bc
  85. pha
  86. lda z80_b
  87. pha
  88. lda z80_c ;- exx
  89. ldx z80_cp
  90. stx z80_c
  91. sta z80_cp
  92. lda z80_b
  93. ldx z80_bp
  94. stx z80_b
  95. sta z80_bp
  96. lda z80_e
  97. ldx z80_ep
  98. stx z80_e
  99. sta z80_ep
  100. lda z80_d
  101. ldx z80_dp
  102. stx z80_d
  103. sta z80_dp
  104. lda z80_l
  105. ldx z80_lp
  106. stx z80_l
  107. sta z80_lp
  108. lda z80_h
  109. ldx z80_hp
  110. stx z80_h
  111. sta z80_hp
  112. pla ;- pop de
  113. sta z80_d
  114. pla
  115. sta z80_e
  116. lda z80_a ;- ld h,a
  117. sta z80_h
  118. lda z80_c ;- ld l,c
  119. sta z80_l
  120. rts ;- ret