Skip to content

Commit 98d1d83

Browse files
committed
tests: add mul32 test for zxnext arch
1 parent e1615f1 commit 98d1d83

8 files changed

Lines changed: 299 additions & 0 deletions

File tree

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
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+
_b:
19+
DEFB 00, 00
20+
.core.ZXBASIC_USER_DATA_END:
21+
.core.__MAIN_PROGRAM__:
22+
ld hl, 0
23+
ld (_b), hl
24+
ld hl, (_a)
25+
ld (_b), hl
26+
ld hl, 0
27+
ld (_b), hl
28+
ld hl, (_a)
29+
ld (_b), hl
30+
ld de, (_a)
31+
ld hl, (_a)
32+
call .core.__MUL16_FAST
33+
ld (_b), hl
34+
ld hl, 0
35+
ld b, h
36+
ld c, l
37+
.core.__END_PROGRAM:
38+
di
39+
ld hl, (.core.__CALL_BACK__)
40+
ld sp, hl
41+
pop iy
42+
ei
43+
ret
44+
;; --- end of user code ---
45+
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/mul16.asm"
46+
push namespace core
47+
__MUL16: ; Multiplies HL with the last value stored into de stack
48+
; Works for both signed and unsigned
49+
PROC
50+
ex de, hl
51+
pop hl ; Return address
52+
ex (sp), hl ; CALLEE caller convention
53+
__MUL16_FAST:
54+
ld a,d ; a = xh
55+
ld d,h ; d = yh
56+
ld h,a ; h = xh
57+
ld c,e ; c = xl
58+
ld b,l ; b = yl
59+
mul d,e ; yh * yl
60+
ex de,hl
61+
mul d,e ; xh * yl
62+
add hl,de ; add cross products
63+
ld e,c
64+
ld d,b
65+
mul d,e ; yl * xl
66+
ld a,l ; cross products lsb
67+
add a,d ; add to msb final
68+
ld h,a
69+
ld l,e ; hl = final
70+
ret ; Result in hl (16 lower bits)
71+
ENDP
72+
pop namespace
73+
#line 25 "arch/zxnext/mul32.bas"
74+
END
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
' TEST for ADD16
2+
3+
DIM a as UInteger
4+
DIM b as UInteger
5+
6+
b = a * 0
7+
b = a * 1
8+
b = 0 * a
9+
b = 1 * a
10+
b = a * a
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
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+
ex de, hl
24+
ld hl, (_a)
25+
call .core.__MUL16_FAST
26+
ld (_a), hl
27+
ld hl, 0
28+
ld b, h
29+
ld c, l
30+
.core.__END_PROGRAM:
31+
di
32+
ld hl, (.core.__CALL_BACK__)
33+
ld sp, hl
34+
pop iy
35+
ei
36+
ret
37+
;; --- end of user code ---
38+
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/mul16.asm"
39+
push namespace core
40+
__MUL16: ; Multiplies HL with the last value stored into de stack
41+
; Works for both signed and unsigned
42+
PROC
43+
ex de, hl
44+
pop hl ; Return address
45+
ex (sp), hl ; CALLEE caller convention
46+
__MUL16_FAST:
47+
ld a,d ; a = xh
48+
ld d,h ; d = yh
49+
ld h,a ; h = xh
50+
ld c,e ; c = xl
51+
ld b,l ; b = yl
52+
mul d,e ; yh * yl
53+
ex de,hl
54+
mul d,e ; xh * yl
55+
add hl,de ; add cross products
56+
ld e,c
57+
ld d,b
58+
mul d,e ; yl * xl
59+
ld a,l ; cross products lsb
60+
add a,d ; add to msb final
61+
ld h,a
62+
ld l,e ; hl = final
63+
ret ; Result in hl (16 lower bits)
64+
ENDP
65+
pop namespace
66+
#line 20 "arch/zxnext/mul32a.bas"
67+
END
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
REM another MUL16 test
3+
DIM a As Integer
4+
a = a * a * a
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
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
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
2+
REM another ADD16 tests
3+
DIM a As Integer
4+
a = a * a * (a * 2 * a)
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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 hl, (_a)
21+
ld de, -1
22+
call .core.__MUL16_FAST
23+
ld (_a), hl
24+
ld hl, 0
25+
ld b, h
26+
ld c, l
27+
.core.__END_PROGRAM:
28+
di
29+
ld hl, (.core.__CALL_BACK__)
30+
ld sp, hl
31+
pop iy
32+
ei
33+
ret
34+
;; --- end of user code ---
35+
#line 1 "/zxbasic/src/lib/arch/zxnext/runtime/arith/mul16.asm"
36+
push namespace core
37+
__MUL16: ; Multiplies HL with the last value stored into de stack
38+
; Works for both signed and unsigned
39+
PROC
40+
ex de, hl
41+
pop hl ; Return address
42+
ex (sp), hl ; CALLEE caller convention
43+
__MUL16_FAST:
44+
ld a,d ; a = xh
45+
ld d,h ; d = yh
46+
ld h,a ; h = xh
47+
ld c,e ; c = xl
48+
ld b,l ; b = yl
49+
mul d,e ; yh * yl
50+
ex de,hl
51+
mul d,e ; xh * yl
52+
add hl,de ; add cross products
53+
ld e,c
54+
ld d,b
55+
mul d,e ; yl * xl
56+
ld a,l ; cross products lsb
57+
add a,d ; add to msb final
58+
ld h,a
59+
ld l,e ; hl = final
60+
ret ; Result in hl (16 lower bits)
61+
ENDP
62+
pop namespace
63+
#line 17 "arch/zxnext/mul32c.bas"
64+
END
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
DIM a as Integer
2+
3+
a = -1 * a

0 commit comments

Comments
 (0)