summaryrefslogtreecommitdiff
path: root/asm.py
diff options
context:
space:
mode:
Diffstat (limited to 'asm.py')
-rwxr-xr-x[-rw-r--r--]asm.py12
1 files changed, 10 insertions, 2 deletions
diff --git a/asm.py b/asm.py
index 7a20f8b..26eaf8f 100644..100755
--- a/asm.py
+++ b/asm.py
@@ -1,3 +1,5 @@
+#!/usr/bin/env python3
+
mnems = """
nop
rot
@@ -60,15 +62,17 @@ def assemble_line(args, lineno):
emit_call(labels[label])
case ["c", label]:
label_wants[label].add((pc,call_instr))
- emit(0)
+ emit(0x8000)
case ['b', label] if label in local_labels:
emit_obranch(local_labels[label])
case ['b', label]:
local_label_wants[label].add((pc, obranch_instr))
+ emit(0x5000)
case ['j', label] if label in local_labels:
emit_jump(local_labels[label])
case ['j', label]:
local_label_wants[label].add((pc, jump_instr))
+ emit(0x4000)
case ["i", i1]:
assemble_line(["i", i1, "nop"], lineno)
@@ -78,6 +82,7 @@ def assemble_line(args, lineno):
emit_instrs(opc1, opc2)
case ["l", val]:
emit_lit(int(val))
+
case [':', label]:
if label in labels:
raise Wrong(lineno, "label defined twice "+label)
@@ -117,12 +122,15 @@ def emit_jump(addr):
emit(jump_instr(addr, origin=pc))
def emit(word):
+ oldlen = len(output)
output.extend(word.to_bytes(2))
global pc
pc += 2
+ assert len(output) == 2 + oldlen, "beeite"
def put_at(addr, word):
- output[addr:addr+1] = word.to_bytes(2)
+ assert addr % 2 == 0, "ooeu"
+ output[addr:addr+2] = word.to_bytes(2)
def lit_instr(val):
return (val&0b1111111111111) | 0b0110000000000000