Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/arch/z80/visitor/translator_inst_visitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
43 changes: 43 additions & 0 deletions tests/functional/arch/zx48k/shlu16.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions tests/functional/arch/zx48k/shlu16.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ a = a << b
a = a << 1
a = a << 0
a = 0 << b
a = (a = a) << b
a = a << (b = b)

71 changes: 69 additions & 2 deletions tests/functional/arch/zx48k/shlu32.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
3 changes: 3 additions & 0 deletions tests/functional/arch/zx48k/shlu32.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ a = a << b
a = a << 1
a = a << 0
a = 0 << b
a = (a = a) << b
a = a << (b = b)

33 changes: 33 additions & 0 deletions tests/functional/arch/zx48k/shlu8.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions tests/functional/arch/zx48k/shlu8.bas
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ a = a << b
a = a << 1
a = a << 0
a = 0 << b
a = (a = a) << b
a = a << (b = b)

Loading