|
16 | 16 | from src.arch.z80.backend.runtime import Labels as RuntimeLabel |
17 | 17 |
|
18 | 18 |
|
19 | | -# ----------------------------------------------------- |
20 | | -# 16 bits operands |
21 | | -# ----------------------------------------------------- |
22 | | -def int16(op): |
23 | | - """Returns a 16 bit operand converted to 16 bits unsigned int. |
24 | | - Negative numbers are returned in 2 complement. |
25 | | - """ |
26 | | - return int(op) & 0xFFFF |
27 | | - |
28 | | - |
29 | 19 | class Bits16: |
30 | 20 | """Implementation of 16bit operations.""" |
31 | 21 |
|
| 22 | + @classmethod |
| 23 | + def int16(cls, op): |
| 24 | + """Returns a 16 bit operand converted to 16 bits unsigned int. |
| 25 | + Negative numbers are returned in 2 complement. |
| 26 | + """ |
| 27 | + return int(op) & 0xFFFF |
| 28 | + |
32 | 29 | @classmethod |
33 | 30 | def get_oper(cls, op1, op2=None, *, reversed: bool = False): |
34 | 31 | """Returns pop sequence for 16 bits operands |
@@ -63,7 +60,7 @@ def get_oper(cls, op1, op2=None, *, reversed: bool = False): |
63 | 60 | if indirect: |
64 | 61 | output.append("ld hl, (%i)" % op) |
65 | 62 | else: |
66 | | - output.append("ld hl, %i" % int16(op)) |
| 63 | + output.append("ld hl, %i" % cls.int16(op)) |
67 | 64 | else: |
68 | 65 | if immediate: |
69 | 66 | if indirect: |
@@ -104,7 +101,7 @@ def get_oper(cls, op1, op2=None, *, reversed: bool = False): |
104 | 101 | if indirect: |
105 | 102 | output.append("ld de, (%i)" % op) |
106 | 103 | else: |
107 | | - output.append("ld de, %i" % int16(op)) |
| 104 | + output.append("ld de, %i" % cls.int16(op)) |
108 | 105 | else: |
109 | 106 | if immediate: |
110 | 107 | output.append("ld de, %s" % op) |
@@ -145,7 +142,7 @@ def add16(cls, ins: Quad) -> list[str]: |
145 | 142 | op1, op2 = tuple(ins[2:]) |
146 | 143 | if _int_ops(op1, op2) is not None: |
147 | 144 | op1, op2 = _int_ops(op1, op2) |
148 | | - op2 = int16(op2) |
| 145 | + op2 = cls.int16(op2) |
149 | 146 | output = Bits16.get_oper(op1) |
150 | 147 |
|
151 | 148 | if op2 == 0: |
@@ -194,7 +191,7 @@ def sub16(cls, ins: Quad) -> list[str]: |
194 | 191 | op1, op2 = tuple(ins[2:4]) |
195 | 192 |
|
196 | 193 | if is_int(op2): |
197 | | - op = int16(op2) |
| 194 | + op = cls.int16(op2) |
198 | 195 | output = Bits16.get_oper(op1) |
199 | 196 |
|
200 | 197 | if op == 0: |
@@ -302,7 +299,7 @@ def divu16(cls, ins: Quad) -> list[str]: |
302 | 299 | return output |
303 | 300 |
|
304 | 301 | if is_int(op2): |
305 | | - op = int16(op2) |
| 302 | + op = cls.int16(op2) |
306 | 303 | output = Bits16.get_oper(op1) |
307 | 304 |
|
308 | 305 | if op2 == 0: # A * 0 = 0 * A = 0 |
@@ -361,7 +358,7 @@ def divi16(cls, ins: Quad) -> list[str]: |
361 | 358 | return output |
362 | 359 |
|
363 | 360 | if is_int(op2): |
364 | | - op = int16(op2) |
| 361 | + op = cls.int16(op2) |
365 | 362 | output = Bits16.get_oper(op1) |
366 | 363 |
|
367 | 364 | if op == 1: |
@@ -403,7 +400,7 @@ def modu16(cls, ins: Quad) -> list[str]: |
403 | 400 | op1, op2 = tuple(ins[2:]) |
404 | 401 |
|
405 | 402 | if is_int(op2): |
406 | | - op2 = int16(op2) |
| 403 | + op2 = cls.int16(op2) |
407 | 404 | output = Bits16.get_oper(op1) |
408 | 405 |
|
409 | 406 | if op2 == 1: |
@@ -448,7 +445,7 @@ def modi16(cls, ins: Quad) -> list[str]: |
448 | 445 | op1, op2 = tuple(ins[2:]) |
449 | 446 |
|
450 | 447 | if is_int(op2): |
451 | | - op2 = int16(op2) |
| 448 | + op2 = cls.int16(op2) |
452 | 449 | output = Bits16.get_oper(op1) |
453 | 450 |
|
454 | 451 | if op2 == 1: |
@@ -888,7 +885,7 @@ def shru16(cls, ins: Quad) -> list[str]: |
888 | 885 | label2 = tmp_label() |
889 | 886 |
|
890 | 887 | if is_int(op2): |
891 | | - op = int16(op2) |
| 888 | + op = cls.int16(op2) |
892 | 889 | if op == 0: |
893 | 890 | return [] |
894 | 891 |
|
@@ -932,7 +929,7 @@ def shri16(cls, ins: Quad) -> list[str]: |
932 | 929 | label2 = tmp_label() |
933 | 930 |
|
934 | 931 | if is_int(op2): |
935 | | - op = int16(op2) |
| 932 | + op = cls.int16(op2) |
936 | 933 | if op == 0: |
937 | 934 | return [] |
938 | 935 |
|
@@ -976,7 +973,7 @@ def shl16(cls, ins: Quad) -> list[str]: |
976 | 973 | label2 = tmp_label() |
977 | 974 |
|
978 | 975 | if is_int(op2): |
979 | | - op = int16(op2) |
| 976 | + op = cls.int16(op2) |
980 | 977 | if op == 0: |
981 | 978 | return [] |
982 | 979 |
|
|
0 commit comments