diff --git a/src/arch/z80/visitor/translator_inst_visitor.py b/src/arch/z80/visitor/translator_inst_visitor.py index bb4336b4c..1e023ec0e 100644 --- a/src/arch/z80/visitor/translator_inst_visitor.py +++ b/src/arch/z80/visitor/translator_inst_visitor.py @@ -223,7 +223,7 @@ def ic_return(self, addr) -> None: self.emit("ret", addr) def ic_shl(self, type_: TYPE | sym.BASICTYPE, t, t1, t2) -> None: - self.emit("shl" + self.TSUFFIX(type_), t, t1, t2) + self.emit(f"shl{self._no_bool(type_)}", t, t1, t2) def ic_shr(self, type_: TYPE | sym.BASICTYPE, t, t1, t2) -> None: self.emit("shr" + self.TSUFFIX(type_), t, t1, t2) diff --git a/tests/functional/arch/zx48k/shlu16.asm b/tests/functional/arch/zx48k/shlu16.asm index 79acb3428..e3f010b6a 100644 --- a/tests/functional/arch/zx48k/shlu16.asm +++ b/tests/functional/arch/zx48k/shlu16.asm @@ -42,6 +42,38 @@ _b: xor a ld l, a ld h, 0 + ld (_a), hl + ld de, (_a) + ld hl, (_a) + call .core.__EQ16 + push af + ld a, (_b) + pop hl + or a + ld b, a + ld a, h + jr z, .LABEL.__LABEL7 +.LABEL.__LABEL6: + add a, a + djnz .LABEL.__LABEL6 +.LABEL.__LABEL7: + ld l, a + ld h, 0 + ld (_a), hl + ld hl, (_b - 1) + ld a, (_b) + sub h + sub 1 + sbc a, a + neg + ld b, a + ld hl, (_a) + or a + jr z, .LABEL.__LABEL9 +.LABEL.__LABEL8: + add hl, hl + djnz .LABEL.__LABEL8 +.LABEL.__LABEL9: ld (_a), hl ld hl, 0 ld b, h @@ -58,4 +90,15 @@ _b: ei ret ;; --- end of user code --- +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/eq16.asm" + push namespace core +__EQ16: ; Test if 16bit values HL == DE + ; Returns result in A: 0 = False, FF = True + xor a ; Reset carry flag + sbc hl, de + ret nz + inc a + ret + pop namespace +#line 68 "arch/zx48k/shlu16.bas" END diff --git a/tests/functional/arch/zx48k/shlu16.bas b/tests/functional/arch/zx48k/shlu16.bas index 3fccb9089..3e44daa14 100644 --- a/tests/functional/arch/zx48k/shlu16.bas +++ b/tests/functional/arch/zx48k/shlu16.bas @@ -5,3 +5,6 @@ a = a << b a = a << 1 a = a << 0 a = 0 << b +a = (a = a) << b +a = a << (b = b) + diff --git a/tests/functional/arch/zx48k/shlu32.asm b/tests/functional/arch/zx48k/shlu32.asm index 039183096..b8c321254 100644 --- a/tests/functional/arch/zx48k/shlu32.asm +++ b/tests/functional/arch/zx48k/shlu32.asm @@ -51,6 +51,47 @@ _b: ld h, 0 ld e, h ld d, h + ld (_a), hl + ld (_a + 2), de + ld hl, (_a + 2) + push hl + ld hl, (_a) + push hl + ld hl, (_a) + ld de, (_a + 2) + call .core.__EQ32 + push af + ld a, (_b) + pop hl + or a + ld b, a + ld a, h + jr z, .LABEL.__LABEL3 +.LABEL.__LABEL2: + add a, a + djnz .LABEL.__LABEL2 +.LABEL.__LABEL3: + ld l, a + ld h, 0 + ld e, h + ld d, h + ld (_a), hl + ld (_a + 2), de + ld hl, (_b - 1) + ld a, (_b) + sub h + sub 1 + sbc a, a + neg + ld b, a + ld hl, (_a) + ld de, (_a + 2) + or a + jr z, .LABEL.__LABEL5 +.LABEL.__LABEL4: + call .core.__SHL32 + djnz .LABEL.__LABEL4 +.LABEL.__LABEL5: ld (_a), hl ld (_a + 2), de ld hl, 0 @@ -68,7 +109,7 @@ _b: ei ret ;; --- end of user code --- -#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/shl32.asm" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/bitwise/shl32.asm" push namespace core __SHL32: ; Left Logical Shift 32 bits sla l @@ -77,5 +118,31 @@ __SHL32: ; Left Logical Shift 32 bits rl d ret pop namespace -#line 46 "arch/zx48k/shlu32.bas" +#line 87 "arch/zx48k/shlu32.bas" +#line 1 "/zxbasic/src/lib/arch/zx48k/runtime/cmp/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 88 "arch/zx48k/shlu32.bas" END diff --git a/tests/functional/arch/zx48k/shlu32.bas b/tests/functional/arch/zx48k/shlu32.bas index 3e39ce8a5..3e8914a82 100644 --- a/tests/functional/arch/zx48k/shlu32.bas +++ b/tests/functional/arch/zx48k/shlu32.bas @@ -5,3 +5,6 @@ a = a << b a = a << 1 a = a << 0 a = 0 << b +a = (a = a) << b +a = a << (b = b) + diff --git a/tests/functional/arch/zx48k/shlu8.asm b/tests/functional/arch/zx48k/shlu8.asm index eaa74c9c3..eee1cb31d 100644 --- a/tests/functional/arch/zx48k/shlu8.asm +++ b/tests/functional/arch/zx48k/shlu8.asm @@ -40,6 +40,39 @@ _b: ld (_a), a ld a, (_b) xor a + ld (_a), a + ld hl, (_a - 1) + ld a, (_a) + sub h + sub 1 + sbc a, a + push af + ld a, (_b) + pop hl + or a + ld b, a + ld a, h + jr z, .LABEL.__LABEL3 +.LABEL.__LABEL2: + add a, a + djnz .LABEL.__LABEL2 +.LABEL.__LABEL3: + ld (_a), a + ld hl, (_b - 1) + ld a, (_b) + sub h + sub 1 + sbc a, a + neg + ld hl, (_a - 1) + or a + ld b, a + ld a, h + jr z, .LABEL.__LABEL5 +.LABEL.__LABEL4: + add a, a + djnz .LABEL.__LABEL4 +.LABEL.__LABEL5: ld (_a), a ld hl, 0 ld b, h diff --git a/tests/functional/arch/zx48k/shlu8.bas b/tests/functional/arch/zx48k/shlu8.bas index f1ae30b1e..f95cee673 100644 --- a/tests/functional/arch/zx48k/shlu8.bas +++ b/tests/functional/arch/zx48k/shlu8.bas @@ -5,3 +5,6 @@ a = a << b a = a << 1 a = a << 0 a = 0 << b +a = (a = a) << b +a = a << (b = b) +