Esempio n. 1
0
File: Swp.cs Progetto: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     var swap = chip.Acc.Read();
      chip.Acc.Write(chip.Bak.Read());
      chip.Bak.Write(swap);
      return OperationResult.Advance;
 }
Esempio n. 2
0
File: Jgz.cs Progetto: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            if (chip.Acc.Read().ToInteger() > 0) {
                 chip.Ip = Ip;
                 return OperationResult.Jump;
             }

             return OperationResult.Advance;
        }
Esempio n. 3
0
File: Sub.cs Progetto: embix/TIS100
        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;
        }
Esempio n. 4
0
File: Jro.cs Progetto: embix/TIS100
        public IOperationResult Execute(AssemblyChip chip)
        {
            var rw = Source.Reference(chip);

             if (rw.IsReadyToRead()) {
                 chip.Ip += rw.Read().ToInteger();
                 return OperationResult.Jump;
             }

             return OperationResult.Block;
        }
Esempio n. 5
0
File: Mov.cs Progetto: embix/TIS100
        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;
        }
Esempio n. 6
0
        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());
        }
Esempio n. 7
0
        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());
        }
Esempio n. 8
0
File: Neg.cs Progetto: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     chip.Acc.Write(-chip.Acc.Read());
      return OperationResult.Advance;
 }
Esempio n. 9
0
File: Jmp.cs Progetto: embix/TIS100
 public IOperationResult Execute(AssemblyChip chip)
 {
     chip.Ip = Ip;
     return OperationResult.Jump;
 }
Esempio n. 10
0
 protected void NormalizeIp(AssemblyChip chip)
 {
     if (chip.Ip < 0 || chip.Ip >= chip.Operations.Count) {
         chip.Ip = 0;
     }
 }
Esempio n. 11
0
 public abstract void Apply(AssemblyChip chip);
Esempio n. 12
0
 public override void Apply(AssemblyChip chip)
 {
     chip.Status = ChipStatus.Executing;
     NormalizeIp(chip);
 }
Esempio n. 13
0
 public override void Apply(AssemblyChip chip)
 {
     chip.Status = ChipStatus.Blocked;
 }