Skip to content

Commit 8d11dae

Browse files
authored
Merge pull request #539 from boriel/bugfix/shift_operator_broken
Bugfix/shift operator broken
2 parents 34ca4d1 + e7ae259 commit 8d11dae

7 files changed

Lines changed: 171 additions & 12 deletions

File tree

src/arch/zx48k/backend/__16bit.py

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -886,6 +886,9 @@ def _shru16(ins):
886886
Shift Right Arithmetic
887887
"""
888888
op1, op2 = tuple(ins.quad[2:])
889+
label = tmp_label()
890+
label2 = tmp_label()
891+
889892
if is_int(op2):
890893
op = int16(op2)
891894
if op == 0:
@@ -903,11 +906,9 @@ def _shru16(ins):
903906
output = _8bit_oper(op2)
904907
output.append('ld b, a')
905908
output.extend(_16bit_oper(op1))
909+
output.append('or a')
910+
output.append('jr z, %s' % label2)
906911

907-
label = tmp_label()
908-
label2 = tmp_label()
909-
output.append('or a')
910-
output.append('jr z, %s' % label2)
911912
output.append('%s:' % label)
912913
output.append('srl h')
913914
output.append('rr l')
@@ -929,6 +930,9 @@ def _shri16(ins):
929930
Shift Right Arithmetic
930931
"""
931932
op1, op2 = tuple(ins.quad[2:])
933+
label = tmp_label()
934+
label2 = tmp_label()
935+
932936
if is_int(op2):
933937
op = int16(op2)
934938
if op == 0:
@@ -946,11 +950,9 @@ def _shri16(ins):
946950
output = _8bit_oper(op2)
947951
output.append('ld b, a')
948952
output.extend(_16bit_oper(op1))
953+
output.append('or a')
954+
output.append('jr z, %s' % label2)
949955

950-
label = tmp_label()
951-
label2 = tmp_label()
952-
output.append('or a')
953-
output.append('jr z, %s' % label2)
954956
output.append('%s:' % label)
955957
output.append('sra h')
956958
output.append('rr l')
@@ -972,6 +974,9 @@ def _shl16(ins):
972974
unroll lop
973975
"""
974976
op1, op2 = tuple(ins.quad[2:])
977+
label = tmp_label()
978+
label2 = tmp_label()
979+
975980
if is_int(op2):
976981
op = int16(op2)
977982
if op == 0:
@@ -988,11 +993,9 @@ def _shl16(ins):
988993
output = _8bit_oper(op2)
989994
output.append('ld b, a')
990995
output.extend(_16bit_oper(op1))
996+
output.append('or a')
997+
output.append('jr z, %s' % label2)
991998

992-
label = tmp_label()
993-
label2 = tmp_label()
994-
output.append('or a')
995-
output.append('jr z, %s' % label2)
996999
output.append('%s:' % label)
9971000
output.append('add hl, hl')
9981001
output.append('djnz %s' % label)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
org 32768
2+
.core.__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 (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
_num1:
22+
DEFB 00, 00
23+
_num2:
24+
DEFB 00, 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld hl, (_num1)
28+
ld b, 3
29+
.LABEL.__LABEL0:
30+
sra h
31+
rr l
32+
djnz .LABEL.__LABEL0
33+
.LABEL.__LABEL1:
34+
ld (_num2), hl
35+
ld hl, 0
36+
ld b, h
37+
ld c, l
38+
.core.__END_PROGRAM:
39+
di
40+
ld hl, (.core.__CALL_BACK__)
41+
ld sp, hl
42+
exx
43+
pop hl
44+
exx
45+
pop iy
46+
pop ix
47+
ei
48+
ret
49+
;; --- end of user code ---
50+
END
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dim num1, num2 as integer
2+
num2 = num1 >> 3
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
org 32768
2+
.core.__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 (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
_num1:
22+
DEFB 00, 00
23+
_num2:
24+
DEFB 00, 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld hl, (_num1)
28+
ld b, 6
29+
.LABEL.__LABEL0:
30+
add hl, hl
31+
djnz .LABEL.__LABEL0
32+
.LABEL.__LABEL1:
33+
ld (_num2), 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+
exx
42+
pop hl
43+
exx
44+
pop iy
45+
pop ix
46+
ei
47+
ret
48+
;; --- end of user code ---
49+
END
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dim num1, num2 as integer
2+
num2 = num1 << 6
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
org 32768
2+
.core.__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 (.core.__CALL_BACK__), hl
12+
ei
13+
jp .core.__MAIN_PROGRAM__
14+
.core.__CALL_BACK__:
15+
DEFW 0
16+
.core.ZXBASIC_USER_DATA:
17+
; Defines USER DATA Length in bytes
18+
.core.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_END - .core.ZXBASIC_USER_DATA
19+
.core.__LABEL__.ZXBASIC_USER_DATA_LEN EQU .core.ZXBASIC_USER_DATA_LEN
20+
.core.__LABEL__.ZXBASIC_USER_DATA EQU .core.ZXBASIC_USER_DATA
21+
_num1:
22+
DEFB 00, 00
23+
_num2:
24+
DEFB 00, 00
25+
.core.ZXBASIC_USER_DATA_END:
26+
.core.__MAIN_PROGRAM__:
27+
ld hl, (_num1)
28+
ld b, 3
29+
.LABEL.__LABEL0:
30+
srl h
31+
rr l
32+
djnz .LABEL.__LABEL0
33+
.LABEL.__LABEL1:
34+
ld (_num2), hl
35+
ld hl, 0
36+
ld b, h
37+
ld c, l
38+
.core.__END_PROGRAM:
39+
di
40+
ld hl, (.core.__CALL_BACK__)
41+
ld sp, hl
42+
exx
43+
pop hl
44+
exx
45+
pop iy
46+
pop ix
47+
ei
48+
ret
49+
;; --- end of user code ---
50+
END
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dim num1, num2 as uinteger
2+
num2 = num1 >> 3
3+

0 commit comments

Comments
 (0)