From 20ddcf5e3733677b695d50d86d65c8de5b386e60 Mon Sep 17 00:00:00 2001 From: ubq323 Date: Thu, 2 May 2024 21:06:41 +0100 Subject: oeu --- asm.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) mode change 100644 => 100755 asm.py (limited to 'asm.py') diff --git a/asm.py b/asm.py old mode 100644 new mode 100755 index 7a20f8b..26eaf8f --- 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 -- cgit v1.2.3