From 6a031fb49d595726da16adcf868475b1e104d60d Mon Sep 17 00:00:00 2001 From: Julian Blake Kongslie Date: Sun, 4 Apr 2021 16:20:24 -0700 Subject: Remove idx, add indirect jumps, renumber opcodes so NOP=0, add absolute labels to asm.rb --- asm.rb | 31 +++++++++++++++---------------- 1 file changed, 15 insertions(+), 16 deletions(-) (limited to 'asm.rb') diff --git a/asm.rb b/asm.rb index c3a0125..4883edb 100755 --- a/asm.rb +++ b/asm.rb @@ -2,20 +2,17 @@ OPCODES = { "i" => 0x080, - "acc=" => 0x000, - "ladd" => 0x100, - "store" => 0x200, - "ifeq" => 0x300, - "jmp" => 0x400, - "ascii" => 0x500, - "++acc" => 0xf01, - "--acc" => 0xf02, - "++idx" => 0xf04, - "--idx" => 0xf08, - "swap" => 0xf10, - "idx" => 0xf20, - "tx" => 0xf40, - "halt" => 0xf80, + "acc=" => 0x100, + "ladd" => 0x200, + "store" => 0x300, + "ifeq" => 0x400, + "jmp" => 0x500, + "ascii" => 0x600, + "cla" => 0x001, + "++acc" => 0x002, + "--acc" => 0x004, + "tx" => 0x040, + "halt" => 0x080, } Line = Struct.new(:opcode, :refs, :code) @@ -56,9 +53,11 @@ end $code.each_with_index() do | line, i | op = line.opcode line.refs.each() do | ref | - if $labels.key?(ref) + if ref =~ /^@(.+)$/ and $labels.key?($1) + op |= $labels[$1] + elsif $labels.key?(ref) target = $labels[ref] - (i + 1) - target += 0x100 if target < 0 + target += 0x80 if target < 0 op |= target else throw "I don't understand #{ref.inspect()}" -- cgit v1.2.3