Fixed issues with CALL/RET.

Added Test Program for CALL/RET.
Fixed MUL instruction.
This commit is contained in:
2017-12-17 22:35:46 +00:00
parent 430bfe4a99
commit 81d5b85f78
8 changed files with 58 additions and 11 deletions

View File

@@ -44,7 +44,8 @@ namespace SVM.Instructions
Debug.Assert(vm.SP < VM.STACKDEPTH); Debug.Assert(vm.SP < VM.STACKDEPTH);
vm.STACK[vm.SP++] = vm.PC; vm.STACK[vm.SP++] = vm.PC;
vm.PC = (ushort)((vars[0] << 8) + vars[1]); var jmp = (ushort)((vars[0] << 8) + vars[1]);
vm.PC = jmp;
} }
public override string ToASM(byte[] vars) public override string ToASM(byte[] vars)

View File

@@ -6,7 +6,7 @@ namespace SVM.Instructions
{ {
class MUL : ADD class MUL : ADD
{ {
public override string ASM => "SUB"; public override string ASM => "MUL";
public override byte OP => 0x24; public override byte OP => 0x24;

View File

@@ -19,10 +19,11 @@ namespace SVM.Instructions
public override void Exec(VM vm, byte[] vars) public override void Exec(VM vm, byte[] vars)
{ {
Debug.Assert(vars.Length == 0); Debug.Assert(vars.Length == 0);
Debug.Assert(vm.SP >= 0); Debug.Assert(vm.SP > 0);
vm.SP--;
vm.PC = vm.STACK[vm.SP]; vm.PC = vm.STACK[vm.SP];
vm.STACK[vm.SP--] = 0; vm.STACK[vm.SP] = 0;
} }
public override string ToASM(byte[] vars) public override string ToASM(byte[] vars)

29
SVM/PGM/CALL.txt Normal file
View File

@@ -0,0 +1,29 @@
ORIGIN 0
JMP :PGM
:WRITESTR
SETI A
:WRITESTR_LOOP
LOADI A
JZ A :WRITESTR_RET
SAVE A P 0
INCI
JMP :WRITESTR_LOOP
:WRITESTR_RET
RET
:WRITENL
LOAD A L 13
SAVE A P 0
LOAD A L 10
SAVE A P 0
RET
:PGM
LOAD A L 0x100
CALL :WRITESTR
CALL :WRITENL
HALT
MEMORY
0x100 "CALL/RET Test"

View File

@@ -7,8 +7,18 @@ namespace SVM
{ {
static void Main(string[] args) static void Main(string[] args)
{ {
if (args.Length == 0)
{
Console.WriteLine("Usage: dotnet SVN.dll [Filename]");
return;
}
var file = Path.Combine(Environment.CurrentDirectory, args[0]); var file = Path.Combine(Environment.CurrentDirectory, args[0]);
if (!File.Exists(file))
{
Console.WriteLine("Error: File Not Found");
}
var content = File.ReadAllText(file); var content = File.ReadAllText(file);
Console.WriteLine("Assembling {0}", file); Console.WriteLine("Assembling {0}", file);
@@ -16,7 +26,8 @@ namespace SVM
var asm = new Assembler(); var asm = new Assembler();
var mem = asm.Compile(content); var mem = asm.Compile(content);
Console.WriteLine("Compiled to {0} bytes", mem.Length);
var vm = new VM(); var vm = new VM();
vm.CycleDelay = 25; vm.CycleDelay = 25;
vm.Load(mem, 0); vm.Load(mem, 0);

View File

@@ -3,14 +3,20 @@
<PropertyGroup> <PropertyGroup>
<OutputType>Exe</OutputType> <OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.0</TargetFramework> <TargetFramework>netcoreapp2.0</TargetFramework>
<StartupObject></StartupObject>
<ApplicationIcon />
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<None Remove="PGM\A.txt" /> <None Remove="PGM\CALL.txt" />
<None Remove="PGM\HELLO.txt" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Content Include="PGM\A.txt"> <Content Include="PGM\CALL.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="PGM\HELLO.txt">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory> <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content> </Content>
</ItemGroup> </ItemGroup>

View File

@@ -69,14 +69,13 @@ namespace SVM
{ {
if (RUN) if (RUN)
{ {
//Get op
var pc = PC; var pc = PC;
var instr = instructions[MEM[PC++]]; var instr = instructions[MEM[PC++]];
byte[] decoded = instr.Decode(this); byte[] decoded = instr.Decode(this);
Console.WriteLine("A{0} B{1} C{2} D{3}", R[0], R[1], R[2], R[3]); //Console.WriteLine("A{0} B{1} C{2} D{3}", R[0], R[1], R[2], R[3]);
Console.WriteLine("0x{0:X4} {1}", pc, instr.ToASM(decoded)); //Console.WriteLine("0x{0:X4} {1}", pc, instr.ToASM(decoded));
instr.Exec(this, decoded); instr.Exec(this, decoded);
Console.ReadKey(true); //Console.ReadKey(true);
} }
} }
} }