diff options
| author | 2023-02-11 20:49:39 +0000 | |
|---|---|---|
| committer | 2023-02-11 20:49:39 +0000 | |
| commit | 5f3275cf2d3e1f371595f3ef15831e2ee788f780 (patch) | |
| tree | 97b2bbe678cc5f45aaca568ff5d4c9edd3a41005 /asm/creole.py | |
| parent | more test (diff) | |
add signed division IDIV
Diffstat (limited to 'asm/creole.py')
| -rw-r--r-- | asm/creole.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/asm/creole.py b/asm/creole.py index 2e323e4..3746003 100644 --- a/asm/creole.py +++ b/asm/creole.py @@ -11,6 +11,11 @@ def word_2c(w): def ti(w): """ Explicitly transform integer into two's compliment representation. """ return w if w >= 0 else word_wc(-w) +def from_2c(w): + """ Turn two's compliment word into Python integer. """ + if (w >> 31) & 1 == 0: + return w + return -word_2c(w) class ArgType(Enum): """ Class denoting the type of an argument to an instruction. """ @@ -86,9 +91,10 @@ class Instruction(Enum): ADD = 3, ArgType.REG, ArgType.VAL, ArgType.VAL MUL = 4, ArgType.REG, ArgType.VAL, ArgType.VAL DIV = 5, ArgType.REG, ArgType.VAL, ArgType.VAL - JL = 6, ArgType.LAB, ArgType.VAL, ArgType.VAL - CLB = 7, ArgType.LAB - SYS = 8, ArgType.VAL + IDIV = 6, ArgType.REG, ArgType.VAL, ArgType.VAL + JL = 7, ArgType.LAB, ArgType.VAL, ArgType.VAL + CLB = 8, ArgType.LAB + SYS = 9, ArgType.VAL def __init__(self, opcode, *args): if opcode > 0x7F or opcode < 0: |
