From 493cbbcf8dfba590811a219f71a886361fb39d2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bartolom=C3=A9=20S=C3=A1nchez=20Salado?= Date: Wed, 9 Oct 2024 20:32:51 +0200 Subject: [PATCH] ref: move store16 function into a class (Bits16) --- src/arch/z80/backend/_16bit.py | 90 +++++++++++++++++----------------- src/arch/z80/backend/main.py | 5 +- 2 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/arch/z80/backend/_16bit.py b/src/arch/z80/backend/_16bit.py index b5b8f2cf3..3b1045f4d 100644 --- a/src/arch/z80/backend/_16bit.py +++ b/src/arch/z80/backend/_16bit.py @@ -1011,33 +1011,23 @@ def load16(cls, ins: Quad) -> list[str]: output.append("push hl") return output + @classmethod + def store16(cls, ins: Quad) -> list[str]: + """Stores 2nd operand content into address of 1st operand. + store16 a, x => *(&a) = x + Use '*' for indirect store on 1st operand. + """ + output = Bits16.get_oper(ins[2]) -def _store16(ins: Quad) -> list[str]: - """Stores 2nd operand content into address of 1st operand. - store16 a, x => *(&a) = x - Use '*' for indirect store on 1st operand. - """ - output = Bits16.get_oper(ins[2]) + value = ins[1] + indirect = False - value = ins[1] - indirect = False + try: + if value[0] == "*": + indirect = True + value = value[1:] - try: - if value[0] == "*": - indirect = True - value = value[1:] - - value = int(value) & 0xFFFF - if indirect: - output.append("ex de, hl") - output.append("ld hl, (%s)" % str(value)) - output.append("ld (hl), e") - output.append("inc hl") - output.append("ld (hl), d") - else: - output.append("ld (%s), hl" % str(value)) - except ValueError: - if value[0] in "_.": + value = int(value) & 0xFFFF if indirect: output.append("ex de, hl") output.append("ld hl, (%s)" % str(value)) @@ -1046,32 +1036,42 @@ def _store16(ins: Quad) -> list[str]: output.append("ld (hl), d") else: output.append("ld (%s), hl" % str(value)) - elif value[0] == "#": - value = value[1:] - if indirect: + except ValueError: + if value[0] in "_.": + if indirect: + output.append("ex de, hl") + output.append("ld hl, (%s)" % str(value)) + output.append("ld (hl), e") + output.append("inc hl") + output.append("ld (hl), d") + else: + output.append("ld (%s), hl" % str(value)) + elif value[0] == "#": + value = value[1:] + if indirect: + output.append("ex de, hl") + output.append("ld hl, (%s)" % str(value)) + output.append("ld (hl), e") + output.append("inc hl") + output.append("ld (hl), d") + else: + output.append("ld (%s), hl" % str(value)) + else: output.append("ex de, hl") - output.append("ld hl, (%s)" % str(value)) + if indirect: + output.append("pop hl") + output.append("ld a, (hl)") + output.append("inc hl") + output.append("ld h, (hl)") + output.append("ld l, a") + else: + output.append("pop hl") + output.append("ld (hl), e") output.append("inc hl") output.append("ld (hl), d") - else: - output.append("ld (%s), hl" % str(value)) - else: - output.append("ex de, hl") - if indirect: - output.append("pop hl") - output.append("ld a, (hl)") - output.append("inc hl") - output.append("ld h, (hl)") - output.append("ld l, a") - else: - output.append("pop hl") - - output.append("ld (hl), e") - output.append("inc hl") - output.append("ld (hl), d") - return output + return output def _jzero16(ins: Quad) -> list[str]: diff --git a/src/arch/z80/backend/main.py b/src/arch/z80/backend/main.py index 153307017..5864deb81 100644 --- a/src/arch/z80/backend/main.py +++ b/src/arch/z80/backend/main.py @@ -35,7 +35,6 @@ _jzero16, _param16, _ret16, - _store16, ) # 32 bit bitwise operations @@ -413,10 +412,10 @@ def _set_quad_table(self): 2, Bits8.store8 ), # STORE nnnn, X -> Stores X at position N (Type of X determines X size) ICInstruction.STOREI16: ICInfo( - 2, _store16 + 2, Bits16.store16 ), # STORE nnnn, X -> Stores X at position N (Type of X determines X size) ICInstruction.STOREU16: ICInfo( - 2, _store16 + 2, Bits16.store16 ), # STORE nnnn, X -> Stores X at position N (Type of X determines X size) ICInstruction.STOREI32: ICInfo( 2, Bits32.store32