From 2001c4fc124beadcb3ed7948be09f5c3d5208dc9 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sat, 6 Nov 2021 17:43:12 -0400 Subject: [PATCH] Fixed shit, added other shit Raw data can be added with db db "Strings" db 123 32 12 32 db 0x12 0x24 0x54 db 0x12 123 32 0x23 Added mov, call, and ret instructions ip register renamed to pc values are now emitted as 16 bits values can now be labels --- zasm.py | 32 +++++++++++++++++++++++++------- 1 file changed, 25 insertions(+), 7 deletions(-) diff --git a/zasm.py b/zasm.py index 3c3cf55..44848e3 100644 --- a/zasm.py +++ b/zasm.py @@ -20,12 +20,15 @@ class Things: 'div': 0x13, 'test': 0x16, 'prt': 0x17, + 'mov': 0x18, + 'call': 0x19, + 'ret': 0x1A, 'je': 0x08, } registers = { - 'ip': 0x00, + 'pc': 0x00, 'sp': 0x01, 'flags': 0x03, 'a': 0x04, @@ -98,7 +101,20 @@ class ZASM: else: line = line[4:] chunks = line.split(' ') - if chunks[0] in Things.opcodes: + print(chunks) + if chunks[0] == 'db': + if chunks[1].startswith('"') and chunks[-1].endswith('"'): + for c in ' '.join(chunks[1:])[1:-1]: + self.emit8(ord(c)) + self.emit8(0) + else: + for c in chunks[1:]: + if c.startswith('0x'): + self.emit8(int(c, 16)) + else: + self.emit8(int(c)) + continue + elif chunks[0] in Things.opcodes: self.emit8(Things.opcodes[chunks[0]]) else: print(f'Unknown opcode: {chunks[0]} at {line_no}: {line}') @@ -125,14 +141,16 @@ class ZASM: # self.set8(self._pc - 2, Things.opcodes[chunks[0]] - 2) # chunk[2] = chunk[2][1:-1] if len(chunks) <= 2: - self.emit8(0) + self.emit16(0) elif chunks[2] in Things.registers: - self.emit8(Things.registers[chunks[2]]) + self.emit16(Things.registers[chunks[2]]) elif chunks[2].startswith('#'): - self.emit8(int(chunks[2][1:])) + self.emit16(int(chunks[2][1:])) else: - print(f'Invalid immediate: {chunks[2]} at {line_no}: {line}') - break + self._to_be_resolved[self._pc] = (chunks[2], line_no, line) + self.emit16(0xDADA) + # print(f'Invalid immediate: {chunks[2]} at {line_no}: {line}') + # break for loc, (label, line_no, line) in self._to_be_resolved.items(): print(loc, label, line_no, line)