Files
SVM/SVM/Instructions/CLR.cs
Sam Stevens cf9004e206 Implemented faults and fault handling.
Added flags FLTSTS, FLTJH, FLTJL.

Added breakpoints and BRK instruction.

Added PUSH and POP instructions for interacting with the stack.
2017-12-31 23:18:17 +00:00

49 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;
namespace SVM.Instructions
{
class CLR : Instruction
{
public override string ASM => "CLR";
public override byte OP => 0x20;
public override byte[] Encode(string asm, Dictionary<string, ushort> markerRefs)
{
Debug.Assert(asm.Length == 1);
byte reg = Register.FromASM(asm);
return new byte[] { OP, reg };
}
public override byte[] Decode(VM vm)
{
return new byte[] { vm.MEM[vm.PC++] };
}
public override void Exec(VM vm, byte[] vars)
{
Debug.Assert(vars.Length == 1);
byte reg = vars[0];
if (reg <= VM.REGISTERS)
{
throw new Fault(FaultType.IllegalOp);
}
Run(vm, reg);
}
protected virtual void Run(VM vm, byte reg)
{
vm.R[reg] = 0;
}
public override string ToASM(byte[] vars)
{
Debug.Assert(vars.Length == 1);
return string.Format("{0} {1}", ASM, Register.ToASM(vars[0]));
}
}
}