Skip to content

Commit 3fdc502

Browse files
authored
Merge pull request #828 from bartsanchez/bart/move-store16-to-a-class
ref: move store16 function into a class (Bits16)
2 parents a76d086 + 493cbbc commit 3fdc502

2 files changed

Lines changed: 47 additions & 48 deletions

File tree

src/arch/z80/backend/_16bit.py

Lines changed: 45 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,33 +1011,23 @@ def load16(cls, ins: Quad) -> list[str]:
10111011
output.append("push hl")
10121012
return output
10131013

1014+
@classmethod
1015+
def store16(cls, ins: Quad) -> list[str]:
1016+
"""Stores 2nd operand content into address of 1st operand.
1017+
store16 a, x => *(&a) = x
1018+
Use '*' for indirect store on 1st operand.
1019+
"""
1020+
output = Bits16.get_oper(ins[2])
10141021

1015-
def _store16(ins: Quad) -> list[str]:
1016-
"""Stores 2nd operand content into address of 1st operand.
1017-
store16 a, x => *(&a) = x
1018-
Use '*' for indirect store on 1st operand.
1019-
"""
1020-
output = Bits16.get_oper(ins[2])
1022+
value = ins[1]
1023+
indirect = False
10211024

1022-
value = ins[1]
1023-
indirect = False
1025+
try:
1026+
if value[0] == "*":
1027+
indirect = True
1028+
value = value[1:]
10241029

1025-
try:
1026-
if value[0] == "*":
1027-
indirect = True
1028-
value = value[1:]
1029-
1030-
value = int(value) & 0xFFFF
1031-
if indirect:
1032-
output.append("ex de, hl")
1033-
output.append("ld hl, (%s)" % str(value))
1034-
output.append("ld (hl), e")
1035-
output.append("inc hl")
1036-
output.append("ld (hl), d")
1037-
else:
1038-
output.append("ld (%s), hl" % str(value))
1039-
except ValueError:
1040-
if value[0] in "_.":
1030+
value = int(value) & 0xFFFF
10411031
if indirect:
10421032
output.append("ex de, hl")
10431033
output.append("ld hl, (%s)" % str(value))
@@ -1046,32 +1036,42 @@ def _store16(ins: Quad) -> list[str]:
10461036
output.append("ld (hl), d")
10471037
else:
10481038
output.append("ld (%s), hl" % str(value))
1049-
elif value[0] == "#":
1050-
value = value[1:]
1051-
if indirect:
1039+
except ValueError:
1040+
if value[0] in "_.":
1041+
if indirect:
1042+
output.append("ex de, hl")
1043+
output.append("ld hl, (%s)" % str(value))
1044+
output.append("ld (hl), e")
1045+
output.append("inc hl")
1046+
output.append("ld (hl), d")
1047+
else:
1048+
output.append("ld (%s), hl" % str(value))
1049+
elif value[0] == "#":
1050+
value = value[1:]
1051+
if indirect:
1052+
output.append("ex de, hl")
1053+
output.append("ld hl, (%s)" % str(value))
1054+
output.append("ld (hl), e")
1055+
output.append("inc hl")
1056+
output.append("ld (hl), d")
1057+
else:
1058+
output.append("ld (%s), hl" % str(value))
1059+
else:
10521060
output.append("ex de, hl")
1053-
output.append("ld hl, (%s)" % str(value))
1061+
if indirect:
1062+
output.append("pop hl")
1063+
output.append("ld a, (hl)")
1064+
output.append("inc hl")
1065+
output.append("ld h, (hl)")
1066+
output.append("ld l, a")
1067+
else:
1068+
output.append("pop hl")
1069+
10541070
output.append("ld (hl), e")
10551071
output.append("inc hl")
10561072
output.append("ld (hl), d")
1057-
else:
1058-
output.append("ld (%s), hl" % str(value))
1059-
else:
1060-
output.append("ex de, hl")
1061-
if indirect:
1062-
output.append("pop hl")
1063-
output.append("ld a, (hl)")
1064-
output.append("inc hl")
1065-
output.append("ld h, (hl)")
1066-
output.append("ld l, a")
1067-
else:
1068-
output.append("pop hl")
1069-
1070-
output.append("ld (hl), e")
1071-
output.append("inc hl")
1072-
output.append("ld (hl), d")
10731073

1074-
return output
1074+
return output
10751075

10761076

10771077
def _jzero16(ins: Quad) -> list[str]:

src/arch/z80/backend/main.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
_jzero16,
3636
_param16,
3737
_ret16,
38-
_store16,
3938
)
4039

4140
# 32 bit bitwise operations
@@ -413,10 +412,10 @@ def _set_quad_table(self):
413412
2, Bits8.store8
414413
), # STORE nnnn, X -> Stores X at position N (Type of X determines X size)
415414
ICInstruction.STOREI16: ICInfo(
416-
2, _store16
415+
2, Bits16.store16
417416
), # STORE nnnn, X -> Stores X at position N (Type of X determines X size)
418417
ICInstruction.STOREU16: ICInfo(
419-
2, _store16
418+
2, Bits16.store16
420419
), # STORE nnnn, X -> Stores X at position N (Type of X determines X size)
421420
ICInstruction.STOREI32: ICInfo(
422421
2, Bits32.store32

0 commit comments

Comments
 (0)