|
| 1 | + org 32768 |
| 2 | +.core.__START_PROGRAM: |
| 3 | + di |
| 4 | + push iy |
| 5 | + ld iy, 0x5C3A ; ZX Spectrum ROM variables address |
| 6 | + ld (.core.__CALL_BACK__), sp |
| 7 | + ei |
| 8 | + jp .core.__MAIN_PROGRAM__ |
| 9 | +.core.__CALL_BACK__: |
| 10 | + DEFW 0 |
| 11 | +.core.ZXBASIC_USER_DATA: |
| 12 | + ; Defines USER DATA Length in bytes |
| 13 | +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA |
| 14 | + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN |
| 15 | + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA |
| 16 | +_a: |
| 17 | + DEFB 00, 00 |
| 18 | +.core.ZXBASIC_USER_DATA_END: |
| 19 | +.core.__MAIN_PROGRAM__: |
| 20 | + ld de, (_a) |
| 21 | + ld hl, (_a) |
| 22 | + call .core.__MUL16_FAST |
| 23 | + push hl |
| 24 | + ld hl, (_a) |
| 25 | + add hl, hl |
| 26 | + ex de, hl |
| 27 | + ld hl, (_a) |
| 28 | + call .core.__MUL16_FAST |
| 29 | + ex de, hl |
| 30 | + pop hl |
| 31 | + call .core.__MUL16_FAST |
| 32 | + ld (_a), hl |
| 33 | + ld hl, 0 |
| 34 | + ld b, h |
| 35 | + ld c, l |
| 36 | +.core.__END_PROGRAM: |
| 37 | + di |
| 38 | + ld hl, (.core.__CALL_BACK__) |
| 39 | + ld sp, hl |
| 40 | + pop iy |
| 41 | + ei |
| 42 | + ret |
| 43 | + ;; --- end of user code --- |
| 44 | +#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/mul16.asm" |
| 45 | + push namespace core |
| 46 | +__MUL16: ; Multiplies HL with the last value stored into de stack |
| 47 | + ; Works for both signed and unsigned |
| 48 | + PROC |
| 49 | + ex de, hl |
| 50 | + pop hl ; Return address |
| 51 | + ex (sp), hl ; CALLEE caller convention |
| 52 | +__MUL16_FAST: |
| 53 | + ld a,d ; a = xh |
| 54 | + ld d,h ; d = yh |
| 55 | + ld h,a ; h = xh |
| 56 | + ld c,e ; c = xl |
| 57 | + ld b,l ; b = yl |
| 58 | + mul d,e ; yh * yl |
| 59 | + ex de,hl |
| 60 | + mul d,e ; xh * yl |
| 61 | + add hl,de ; add cross products |
| 62 | + ld e,c |
| 63 | + ld d,b |
| 64 | + mul d,e ; yl * xl |
| 65 | + ld a,l ; cross products lsb |
| 66 | + add a,d ; add to msb final |
| 67 | + ld h,a |
| 68 | + ld l,e ; hl = final |
| 69 | + ret ; Result in hl (16 lower bits) |
| 70 | + ENDP |
| 71 | + pop namespace |
| 72 | +#line 26 "arch/zxnext/mul32b.bas" |
| 73 | + END |
0 commit comments