In /vm_test.asm use "offpc label@" instead of "imm.i32 label" for a significant space...
authorNick Downing <nick@ndcode.org>
Mon, 18 Dec 2023 09:11:36 +0000 (20:11 +1100)
committerNick Downing <nick@ndcode.org>
Mon, 18 Dec 2023 09:11:36 +0000 (20:11 +1100)
vm_asm.py
vm_test.asm

index e83f277..0de9eaa 100755 (executable)
--- a/vm_asm.py
+++ b/vm_asm.py
@@ -195,6 +195,43 @@ mnemonics = {
   'trap':              (0x8a, OPERAND_TYPE_NONE),
 }
 
+# these opcodes can be automatically generated by an OPERAND_TYPE_AUTO
+op_to_mnemonic = {
+  0x23: 'offpc.i8',
+  0x24: 'offpc.i16',
+  0x25: 'offpc.i32',
+  0x26: 'adjpc.i8',
+  0x27: 'adjpc.i16',
+  0x28: 'adjpc.i32',
+  0x2b: 'offsp.i8',
+  0x2c: 'offsp.i16',
+  0x2d: 'offsp.i32',
+  0x2e: 'adjsp.i8',
+  0x2f: 'adjsp.i16',
+  0x30: 'adjsp.i32',
+  0x33: 'offix.i8',
+  0x34: 'offix.i16',
+  0x35: 'offix.i32',
+  0x36: 'adjix.i8',
+  0x37: 'adjix.i16',
+  0x38: 'adjix.i32',
+  0x3b: 'offiy.i8',
+  0x3c: 'offiy.i16',
+  0x3d: 'offiy.i32',
+  0x3e: 'adjiy.i8',
+  0x3f: 'adjiy.i16',
+  0x40: 'adjiy.i32',
+  0x7f: 'adjpc.f.i8',
+  0x80: 'adjpc.f.i16',
+  0x81: 'adjpc.f.i32',
+  0x82: 'adjpc.t.i8',
+  0x83: 'adjpc.t.i16',
+  0x84: 'adjpc.t.i32',
+  0x86: 'call.i8',
+  0x87: 'call.i16',
+  0x88: 'call.i32',
+}
+
 # for auto operands
 size_to_operand_type = {
   1: OPERAND_TYPE_I8,
@@ -419,6 +456,7 @@ while True:
 
                 operand_type = size_to_operand_type[size]
                 op += operand_type - OPERAND_TYPE_I8
+                mnemonic = op_to_mnemonic[op]
 
               if pc_rel:
                   next_pc = pc
index 5a8a489..609bef6 100644 (file)
@@ -4,7 +4,7 @@ putchar = -3
 
 main: ; stack alignment 0x10
        ; printing test
-       imm.i32 hello_world
+       offpc hello_world@
        call print_str@
 
        adjsp -0xc
@@ -195,7 +195,7 @@ print_hex_nibble:
        cvt.i32
 
        push
-       imm.i32 print_hex_table
+       offpc print_hex_table@
        add
        ld.i8
 
@@ -242,7 +242,7 @@ print_dec_i128: ; stack alignment 0x10
        push
 
 print_dec_pos:
-       imm.i32 print_dec_buf_end
+       offpc print_dec_buf_end@
        setix
 
        pop.i128
@@ -276,7 +276,7 @@ print_dec_loop1:
        adjix 1
        getix
        push
-       imm.i32 print_dec_buf_end
+       offpc print_dec_buf_end@
        lt.u
        adjpc.t print_dec_loop1@
 
@@ -308,7 +308,7 @@ print_sci_pos:
        ; entry is struct with threshold value (> 1) then scaling value (< 1)
        ; when multiplying it up:
        ; entry is struct with scaling value (> 1) then threshold value (< 1)
-       imm.i32 print_sci_table
+       offpc print_sci_table@
        setix
 
        ; if number is >= 1, exponent is positive and we'll divide it down
@@ -362,7 +362,7 @@ print_sci_no_div:
        adjix 0x20
        getix
        push
-       imm.i32 print_sci_table_end
+       offpc print_sci_table_end@
        lt.u
        adjpc.t print_sci_loop0@
 
@@ -412,7 +412,7 @@ print_sci_no_mul:
        adjix 0x20
        getix
        push
-       imm.i32 print_sci_table_end
+       offpc print_sci_table_end@
        lt.u
        adjpc.t print_sci_loop1@
 
@@ -452,7 +452,7 @@ print_sci_not_zero:
 
 print_sci_no_overflow:
        ; render all 37 digits backwards into buffer
-       imm.i32 print_sci_buf_end
+       offpc print_sci_buf_end@
        setix
 
 print_sci_loop2:
@@ -477,7 +477,7 @@ print_sci_loop2:
 
        getix
        push
-       imm.i32 print_sci_buf
+       offpc print_sci_buf@
        gt.u
        adjpc.t print_sci_loop2@
 
@@ -512,7 +512,7 @@ print_sci_loop3:
        adjix 1
        getix
        push
-       imm.i32 print_sci_buf_end
+       offpc print_sci_buf_end@
        lt.u
        adjpc.t print_sci_loop3@