Преглед изворни кода

Fixed compiler

Fixed bug with flipped operands on 2reg instruction.
Also fixed immidate count for shift instructions for RISC8.
Added DBE instruction, WIP for %include function.
Min пре 6 година
родитељ
комит
4f675a7b43
2 измењених фајлова са 28 додато и 7 уклоњено
  1. 24 3
      tools/asm_compiler.py
  2. 4 4
      tools/risc8asm.py

+ 24 - 3
tools/asm_compiler.py

@@ -70,11 +70,11 @@ class Instruction:
                 raise CompilingError(f"Unable to decode register name {regs[1]}")
             if regs[0] is None:
                 raise CompilingError(f"Unable to decode register name {regs[0]}")
-            instr |= regs[1] << 2 | regs[0]
+            instr |= regs[0] << 2 | regs[1]
         elif len(regs) == 1:
             if regs[0] is None:
                 raise CompilingError(f"Unable to decode register name {regs[0]}")
-            instr |= int(regs[0]) << 2
+            instr |= regs[0] << 2
         return instr.to_bytes(1, 'little')  # Order does not matter with 1 byte
 
     def compile(self, operands, scope):
@@ -297,10 +297,16 @@ class Compiler:
                     self.labels[line_args[1]] = self.decode_bytes(line_args[2])
                     continue
 
+                elif line_args[0].lower() == '%include':
+                    if len(line_args) != 2:
+                        raise CompilingError(f"Invalid %include arguments!")
+                    raise CompilingError(f"%include is not implemented yet")  # TODO: Complete
+                    continue
+
                 if csect is None:
                     raise CompilingError(f"No section defined!")
 
-                builtin_cmds = {'db'}
+                builtin_cmds = {'db', 'dbe'}
 
                 if line_args[0].lower() not in self.instr_db and\
                         line_args[0].lower() not in builtin_cmds:  # Must be label
@@ -333,6 +339,21 @@ class Compiler:
                     csect.count += int(len(data)/csect.width)
                     continue
 
+                if instr_name == 'dbe':
+                    try:
+                        fill = int(args[0])
+                    except ValueError:
+                        raise CompilingError(f"Instruction 'dbe' invalid argument, must be a number")
+                    except IndexError:
+                        raise CompilingError(f"Instruction 'dbe' invalid argument count! Must be 1")
+
+                    if fill % csect.width != 0:
+                        fill += csect.width - (fill % csect.width)
+                    data = b'\x00' * fill
+                    csect.instr.append(data)
+                    csect.count += int(len(data)/csect.width)
+                    continue
+
                 if instr_name not in self.instr_db:
                     raise CompilingError(f"Instruction '{instr_name}' not recognised!")
 

+ 4 - 4
tools/risc8asm.py

@@ -16,7 +16,7 @@ asmc.add_instr(compiler.Instruction('CPY1 ', '0000_0101', 1, alias=['COPY1']))
 asmc.add_instr(compiler.Instruction('CPY2 ', '0000_1010', 1, alias=['COPY2']))
 asmc.add_instr(compiler.Instruction('CPY3 ', '0000_1111', 1, alias=['COPY3']))
 
-asmc.add_instr(compiler.Instruction('MOVE ', '0000_????'))
+asmc.add_instr(compiler.Instruction('MOVE ', '0000_????', alias=['MOV']))
 asmc.add_instr(compiler.Instruction('ADD  ', '0001_????'))
 asmc.add_instr(compiler.Instruction('SUB  ', '0010_????'))
 asmc.add_instr(compiler.Instruction('AND  ', '0011_????'))
@@ -36,9 +36,9 @@ asmc.add_instr(compiler.Instruction('ANDI ', '1110_??10', 1))
 asmc.add_instr(compiler.Instruction('ORI  ', '1110_??11', 1))
 asmc.add_instr(compiler.Instruction('XORI ', '1100_??11', 1))
 
-asmc.add_instr(compiler.Instruction('SLL  ', '1001_??00'))
-asmc.add_instr(compiler.Instruction('SRL  ', '1001_??01'))
-asmc.add_instr(compiler.Instruction('SRA  ', '1001_??10'))
+asmc.add_instr(compiler.Instruction('SLL  ', '1001_??00', 1))
+asmc.add_instr(compiler.Instruction('SRL  ', '1001_??01', 1))
+asmc.add_instr(compiler.Instruction('SRA  ', '1001_??10', 1))
 asmc.add_instr(compiler.Instruction('SRAS ', '1001_??11'))
 asmc.add_instr(compiler.Instruction('LWHI ', '1010_??00', 3))
 asmc.add_instr(compiler.Instruction('SWHI ', '1010_??01'))