|
| 1 | + org 32768 |
| 2 | +.core.__START_PROGRAM: |
| 3 | + di |
| 4 | + push ix |
| 5 | + push iy |
| 6 | + exx |
| 7 | + push hl |
| 8 | + exx |
| 9 | + ld (.core.__CALL_BACK__), sp |
| 10 | + ei |
| 11 | + jp .core.__MAIN_PROGRAM__ |
| 12 | +.core.__CALL_BACK__: |
| 13 | + DEFW 0 |
| 14 | +.core.ZXBASIC_USER_DATA: |
| 15 | + ; Defines USER DATA Length in bytes |
| 16 | +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA |
| 17 | + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN |
| 18 | + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA |
| 19 | +_a: |
| 20 | + DEFB 00, 00, 00, 00 |
| 21 | +.core.ZXBASIC_USER_DATA_END: |
| 22 | +.core.__MAIN_PROGRAM__: |
| 23 | + ld hl, (_a + 2) |
| 24 | + push hl |
| 25 | + ld hl, (_a) |
| 26 | + push hl |
| 27 | + ld hl, (_a) |
| 28 | + ld de, (_a + 2) |
| 29 | + call .core.__MUL32 |
| 30 | + push de |
| 31 | + push hl |
| 32 | + ld hl, (_a) |
| 33 | + ld de, (_a + 2) |
| 34 | + call .core.__MUL32 |
| 35 | + ld (_a), hl |
| 36 | + ld (_a + 2), de |
| 37 | + ld hl, 0 |
| 38 | + ld b, h |
| 39 | + ld c, l |
| 40 | +.core.__END_PROGRAM: |
| 41 | + di |
| 42 | + ld hl, (.core.__CALL_BACK__) |
| 43 | + ld sp, hl |
| 44 | + exx |
| 45 | + pop hl |
| 46 | + exx |
| 47 | + pop iy |
| 48 | + pop ix |
| 49 | + ei |
| 50 | + ret |
| 51 | + ;; --- end of user code --- |
| 52 | +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul32.asm" |
| 53 | +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/arith/_mul32.asm" |
| 54 | +; Ripped from: http://www.andreadrian.de/oldcpu/z80_number_cruncher.html#moztocid784223 |
| 55 | + ; Used with permission. |
| 56 | + ; Multiplies 32x32 bit integer (DEHL x D'E'H'L') |
| 57 | + ; 64bit result is returned in H'L'H L B'C'A C |
| 58 | + push namespace core |
| 59 | +__MUL32_64START: |
| 60 | + push hl |
| 61 | + exx |
| 62 | + ld b, h |
| 63 | + ld c, l ; BC = Low Part (A) |
| 64 | + pop hl ; HL = Load Part (B) |
| 65 | + ex de, hl ; DE = Low Part (B), HL = HightPart(A) (must be in B'C') |
| 66 | + push hl |
| 67 | + exx |
| 68 | + pop bc ; B'C' = HightPart(A) |
| 69 | + exx ; A = B'C'BC , B = D'E'DE |
| 70 | + ; multiply routine 32 * 32bit = 64bit |
| 71 | + ; h'l'hlb'c'ac = b'c'bc * d'e'de |
| 72 | + ; needs register a, changes flags |
| 73 | + ; |
| 74 | + ; this routine was with tiny differences in the |
| 75 | + ; sinclair zx81 rom for the mantissa multiply |
| 76 | +__LMUL: |
| 77 | + xor a ; reset carry flag |
| 78 | + ld h, a ; result bits 32..47 = 0 |
| 79 | + ld l, a |
| 80 | + exx |
| 81 | + ld h, a ; result bits 48..63 = 0 |
| 82 | + ld l, a |
| 83 | + exx |
| 84 | + ld a,b ; mpr is b'c'ac |
| 85 | + ld b,33 ; initialize loop counter |
| 86 | + jp __LMULSTART |
| 87 | +__LMULLOOP: |
| 88 | + jr nc,__LMULNOADD ; JP is 2 cycles faster than JR. Since it's inside a LOOP |
| 89 | + ; it can save up to 33 * 2 = 66 cycles |
| 90 | + ; But JR if 3 cycles faster if JUMP not taken! |
| 91 | + add hl,de ; result += mpd |
| 92 | + exx |
| 93 | + adc hl,de |
| 94 | + exx |
| 95 | +__LMULNOADD: |
| 96 | + exx |
| 97 | + rr h ; right shift upper |
| 98 | + rr l ; 32bit of result |
| 99 | + exx |
| 100 | + rr h |
| 101 | + rr l |
| 102 | +__LMULSTART: |
| 103 | + exx |
| 104 | + rr b ; right shift mpr/ |
| 105 | + rr c ; lower 32bit of result |
| 106 | + exx |
| 107 | + rra ; equivalent to rr a |
| 108 | + rr c |
| 109 | + djnz __LMULLOOP |
| 110 | + ret ; result in h'l'hlb'c'ac |
| 111 | + pop namespace |
| 112 | +#line 2 "/zxbasic/src/lib/arch/zx48k/runtime/arith/mul32.asm" |
| 113 | + push namespace core |
| 114 | +__MUL32: |
| 115 | + ; multiplies 32 bit un/signed integer. |
| 116 | + ; First operand stored in DEHL, and 2nd onto stack |
| 117 | + ; Lowest part of 2nd operand on top of the stack |
| 118 | + ; returns the result in DE.HL |
| 119 | + exx |
| 120 | + pop hl ; Return ADDRESS |
| 121 | + pop de ; Low part |
| 122 | + ex (sp), hl ; CALLEE -> HL = High part |
| 123 | + ex de, hl |
| 124 | + call __MUL32_64START |
| 125 | +__TO32BIT: ; Converts H'L'HLB'C'AC to DEHL (Discards H'L'HL) |
| 126 | + exx |
| 127 | + push bc |
| 128 | + exx |
| 129 | + pop de |
| 130 | + ld h, a |
| 131 | + ld l, c |
| 132 | + ret |
| 133 | + pop namespace |
| 134 | +#line 31 "arch/zx48k/mul32a.bas" |
| 135 | + END |
0 commit comments