Skip to content

Commit 031dde0

Browse files
authored
Merge pull request #490 from boriel/bugfix/eq32
Fix bug with EQ32
2 parents 096622b + d2726a1 commit 031dde0

5 files changed

Lines changed: 155 additions & 1 deletion

File tree

src/arch/zx48k/backend/__32bit.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -564,7 +564,7 @@ def _eq32(ins):
564564
565565
32 bit un/signed version
566566
"""
567-
return _bool_32bit_binary(ins, RuntimeLabel.EQ32, reversible=False)
567+
return _bool_32bit_binary(ins, RuntimeLabel.EQ32, reversible=False, use_int=True)
568568

569569

570570
def _ne32(ins):

tests/functional/equ16.asm

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
_a:
22+
DEFB 00, 00
23+
ZXBASIC_USER_DATA_END:
24+
__MAIN_PROGRAM__:
25+
ld de, 5
26+
ld hl, (_a)
27+
or a
28+
sbc hl, de
29+
jp nz, __LABEL1
30+
ld hl, (_a)
31+
inc hl
32+
ld (_a), hl
33+
__LABEL1:
34+
ld hl, 0
35+
ld b, h
36+
ld c, l
37+
__END_PROGRAM:
38+
di
39+
ld hl, (__CALL_BACK__)
40+
ld sp, hl
41+
exx
42+
pop hl
43+
exx
44+
pop iy
45+
pop ix
46+
ei
47+
ret
48+
;; --- end of user code ---
49+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/eq16.asm"
50+
__EQ16: ; Test if 16bit values HL == DE
51+
; Returns result in A: 0 = False, FF = True
52+
xor a ; Reset carry flag
53+
sbc hl, de
54+
ret nz
55+
inc a
56+
ret
57+
#line 26 "equ16.bas"
58+
END

tests/functional/equ16.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DIM a as UInteger
2+
3+
IF a = 5 THEN
4+
LET a = a + 1
5+
END IF
6+

tests/functional/equ32.asm

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
org 32768
2+
__START_PROGRAM:
3+
di
4+
push ix
5+
push iy
6+
exx
7+
push hl
8+
exx
9+
ld hl, 0
10+
add hl, sp
11+
ld (__CALL_BACK__), hl
12+
ei
13+
jp __MAIN_PROGRAM__
14+
__CALL_BACK__:
15+
DEFW 0
16+
ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_END - ZXBASIC_USER_DATA
19+
.__LABEL__.ZXBASIC_USER_DATA_LEN EQU ZXBASIC_USER_DATA_LEN
20+
.__LABEL__.ZXBASIC_USER_DATA EQU ZXBASIC_USER_DATA
21+
_a:
22+
DEFB 00, 00, 00, 00
23+
ZXBASIC_USER_DATA_END:
24+
__MAIN_PROGRAM__:
25+
ld hl, (_a + 2)
26+
push hl
27+
ld hl, (_a)
28+
push hl
29+
ld de, 0
30+
ld hl, 5
31+
call __EQ32
32+
or a
33+
jp z, __LABEL1
34+
ld de, 0
35+
ld hl, 1
36+
ld bc, (_a)
37+
add hl, bc
38+
ex de, hl
39+
ld bc, (_a + 2)
40+
adc hl, bc
41+
ex de, hl
42+
ld (_a), hl
43+
ld (_a + 2), de
44+
__LABEL1:
45+
ld hl, 0
46+
ld b, h
47+
ld c, l
48+
__END_PROGRAM:
49+
di
50+
ld hl, (__CALL_BACK__)
51+
ld sp, hl
52+
exx
53+
pop hl
54+
exx
55+
pop iy
56+
pop ix
57+
ei
58+
ret
59+
;; --- end of user code ---
60+
#line 1 "/zxbasic/src/arch/zx48k/library-asm/eq32.asm"
61+
__EQ32: ; Test if 32bit value HLDE equals top of the stack
62+
; Returns result in A: 0 = False, FF = True
63+
exx
64+
pop bc ; Return address
65+
exx
66+
xor a ; Reset carry flag
67+
pop bc
68+
sbc hl, bc ; Low part
69+
ex de, hl
70+
pop bc
71+
sbc hl, bc ; High part
72+
exx
73+
push bc ; CALLEE
74+
exx
75+
ld a, h
76+
or l
77+
or d
78+
or e ; a = 0 and Z flag set only if HLDE = 0
79+
ld a, 1
80+
ret z
81+
xor a
82+
ret
83+
#line 37 "equ32.bas"
84+
END

tests/functional/equ32.bas

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
DIM a as ULong
2+
3+
IF a = 5 THEN
4+
LET a = a + 1
5+
END IF
6+

0 commit comments

Comments
 (0)