From 5c461eaa857417b61e880e4bc2e08b36d159c2e1 Mon Sep 17 00:00:00 2001 From: Jose Rodriguez Date: Sun, 20 Oct 2024 11:58:59 +0200 Subject: [PATCH] fix: neq32 had extra push af. Fixed. --- src/arch/z80/backend/_32bit.py | 2 +- tests/functional/arch/zx48k/neq32.asm | 76 +++++++++++++++++++++++++++ tests/functional/arch/zx48k/neq32.bas | 4 ++ 3 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 tests/functional/arch/zx48k/neq32.asm create mode 100644 tests/functional/arch/zx48k/neq32.bas diff --git a/src/arch/z80/backend/_32bit.py b/src/arch/z80/backend/_32bit.py index 96482ea19..5ca27e8b5 100644 --- a/src/arch/z80/backend/_32bit.py +++ b/src/arch/z80/backend/_32bit.py @@ -596,7 +596,7 @@ def ne32(cls, ins: Quad) -> list[str]: 32 bit un/signed version """ - output = cls.eq32(ins) + output = cls.eq32(ins)[:-1] # Compare 32 bits, but do not push result output.append("sub 1") # Carry if A = 0 (False) output.append("sbc a, a") # Negates => !(A == B) output.append("push af") diff --git a/tests/functional/arch/zx48k/neq32.asm b/tests/functional/arch/zx48k/neq32.asm new file mode 100644 index 000000000..6c793db61 --- /dev/null +++ b/tests/functional/arch/zx48k/neq32.asm @@ -0,0 +1,76 @@ + org 32768 +.core.__START_PROGRAM: + di + push ix + push iy + exx + push hl + exx + ld hl, 0 + add hl, sp + ld (.core.__CALL_BACK__), hl + ei + jp .core.__MAIN_PROGRAM__ +.core.__CALL_BACK__: + DEFW 0 +.core.ZXBASIC_USER_DATA: + ; Defines USER DATA Length in bytes +.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA + .core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN + .core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA +_t: + DEFB 00, 00, 00, 00 +.core.ZXBASIC_USER_DATA_END: +.core.__MAIN_PROGRAM__: + ld hl, (_t + 2) + push hl + ld hl, (_t) + push hl + ld de, 0 + ld hl, 0 + call .core.__EQ32 + sub 1 + sbc a, a + ld (0), a + ld hl, 0 + ld b, h + ld c, l +.core.__END_PROGRAM: + di + ld hl, (.core.__CALL_BACK__) + ld sp, hl + exx + pop hl + exx + pop iy + pop ix + ei + ret + ;; --- end of user code --- +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/eq32.asm" + push namespace core +__EQ32: ; Test if 32bit value HLDE equals top of the stack + ; Returns result in A: 0 = False, FF = True + exx + pop bc ; Return address + exx + xor a ; Reset carry flag + pop bc + sbc hl, bc ; Low part + ex de, hl + pop bc + sbc hl, bc ; High part + exx + push bc ; CALLEE + exx + ld a, h + or l + or d + or e ; a = 0 and Z flag set only if HLDE = 0 + ld a, 1 + ret z + xor a + ret + pop namespace +#line 27 "arch/zx48k/neq32.bas" + END diff --git a/tests/functional/arch/zx48k/neq32.bas b/tests/functional/arch/zx48k/neq32.bas new file mode 100644 index 000000000..0c82dbce0 --- /dev/null +++ b/tests/functional/arch/zx48k/neq32.bas @@ -0,0 +1,4 @@ +DIM t as Long + +POKE 0, (t <> 0) +