|
15 | 15 | import re |
16 | 16 |
|
17 | 17 | splitter = re.compile(r",\s*|\s+(?:,\s*)?").split |
| 18 | +mov_splitter = re.compile('!|~|::').split |
18 | 19 |
|
19 | 20 | __version__ = "0.0.0-auto.0" |
20 | 21 | __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_PIOASM.git" |
|
25 | 26 | WAIT_SOURCES = ["gpio", "pin", "irq", None] |
26 | 27 | MOV_DESTINATIONS = ["pins", "x", "y", None, "exec", "pc", "isr", "osr"] |
27 | 28 | MOV_SOURCES = ["pins", "x", "y", "null", None, "status", "isr", "osr"] |
28 | | -MOV_OPS = [None, "~", "::", None] |
29 | 29 | SET_DESTINATIONS = ["pins", "x", "y", None, "pindirs", None, None, None] |
30 | 30 |
|
31 | 31 |
|
@@ -142,9 +142,20 @@ def assemble(text_program): |
142 | 142 | # instr delay dst op src |
143 | 143 | assembled.append(0b101_00000_000_00_000) |
144 | 144 | assembled[-1] |= MOV_DESTINATIONS.index(instruction[1]) << 5 |
145 | | - assembled[-1] |= MOV_SOURCES.index(instruction[-1]) |
146 | | - if len(instruction) > 3: |
147 | | - assembled[-1] |= MOV_OPS.index(instruction[-2]) << 3 |
| 145 | + source = instruction[-1] |
| 146 | + source_split = mov_splitter(source) |
| 147 | + if len(source_split) == 1: |
| 148 | + assembled[-1] |= MOV_SOURCES.index(source) |
| 149 | + else: |
| 150 | + assembled[-1] |= MOV_SOURCES.index(source_split[1]) |
| 151 | + if source[:1] == "!": |
| 152 | + assembled[-1] |= 0x08 |
| 153 | + elif source[:1] == "~": |
| 154 | + assembled[-1] |= 0x08 |
| 155 | + elif source[:2] == "::": |
| 156 | + assembled[-1] |= 0x10 |
| 157 | + else: |
| 158 | + raise RuntimeError("Invalid mov operator:", source[:1]) |
148 | 159 | elif instruction[0] == "irq": |
149 | 160 | # instr delay z c w index |
150 | 161 | assembled.append(0b110_00000_0_0_0_00000) |
|
0 commit comments