public IOperationResult Execute(AssemblyChip chip) { var swap = chip.Acc.Read(); chip.Acc.Write(chip.Bak.Read()); chip.Bak.Write(swap); return OperationResult.Advance; }
public IOperationResult Execute(AssemblyChip chip) { if (chip.Acc.Read().ToInteger() > 0) { chip.Ip = Ip; return OperationResult.Jump; } return OperationResult.Advance; }
public IOperationResult Execute(AssemblyChip chip) { var source = Source.Reference(chip); if (source.IsReadyToRead()) { chip.Acc.Write(chip.Acc.Read() - source.Read()); return OperationResult.Advance; } return OperationResult.Block; }
public IOperationResult Execute(AssemblyChip chip) { var rw = Source.Reference(chip); if (rw.IsReadyToRead()) { chip.Ip += rw.Read().ToInteger(); return OperationResult.Jump; } return OperationResult.Block; }
public IOperationResult Execute(AssemblyChip chip) { var source = Source.Reference(chip); var destination = Destination.Reference(chip); if (state == MovState.Reading && source.IsReadyToRead()) { destination.Write(source.Read()); state = MovState.Writing; } if (state == MovState.Writing && destination.IsDoneWriting()) { state = MovState.Reading; return OperationResult.Advance; } return OperationResult.Block; }
public void Sub_Basic_Works() { var board = new Board(); var chip = new AssemblyChip(); var input = new InputRW(new List<int>() { 1, 2, 4, 3 }); var output = new OutputRW(); chip.Operations = new List<IOperation>() { new Mov(new ConnectionRef("UP"), new ConnectionRef("ACC")), new Sub(new ConnectionRef("UP")), new Mov(new ConnectionRef("ACC"), new ConnectionRef("DOWN")), }; board.Install(chip, new Point(0, 0)); chip.Connections["UP"] = input; chip.Connections["DOWN"] = output; board.ExecuteUntilBlocked(); Assert.AreEqual("-1, 1", output.ToString()); }
private void AssertAddOutputMatches(List<int> inQueue, List<int> expectedOutQueue) { var board = new Board(); var chip = new AssemblyChip(); var input = new InputRW(inQueue); var output = new OutputRW(); chip.Operations = new List<IOperation> { new Mov(UP, ACC), new Add(UP), new Mov(ACC, DOWN) }; board.Install(chip, new Point(0, 0)); chip.Connections[UP.RefName] = input; chip.Connections[DOWN.RefName] = output; board.ExecuteUntilBlocked(); var expectedOutput = expectedOutQueue .Select(a => a.ToString()) .Aggregate((a, b) => a + ", " + b); Assert.AreEqual(expectedOutput, output.ToString()); }
public IOperationResult Execute(AssemblyChip chip) { chip.Acc.Write(-chip.Acc.Read()); return OperationResult.Advance; }
public IOperationResult Execute(AssemblyChip chip) { chip.Ip = Ip; return OperationResult.Jump; }
protected void NormalizeIp(AssemblyChip chip) { if (chip.Ip < 0 || chip.Ip >= chip.Operations.Count) { chip.Ip = 0; } }
public abstract void Apply(AssemblyChip chip);
public override void Apply(AssemblyChip chip) { chip.Status = ChipStatus.Executing; NormalizeIp(chip); }
public override void Apply(AssemblyChip chip) { chip.Status = ChipStatus.Blocked; }