Advertisement
babusha

Untitled

Nov 9th, 2011
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.09 KB | None | 0 0
  1.         public void Run()
  2.         {  
  3.             while(ByteCode.Length > VmIP)
  4.             {
  5.                 switch (ByteCode[VmIP])
  6.                 {
  7.                     case (byte) Command.INC:
  8.                         Cells[CellIP]++;
  9.                         break;
  10.                     case (byte) Command.DEC:
  11.                         Cells[CellIP]--;
  12.                         break;
  13.                     case (byte) Command.PRINT:
  14.                         Console.Write((char) Cells[CellIP]);
  15.                         break;
  16.                     case (byte) Command.READ:
  17.                         string input = Console.ReadKey(false).KeyChar.ToString();
  18.                         byte res = Encoding.ASCII.GetBytes(input)[0];
  19.                         if(res == 10) Console.WriteLine();
  20.                         Cells[CellIP] = res;
  21.                         break;
  22.                     case (byte) Command.NEXT:
  23.                         CellIP++;
  24.                         if (CellIP == 30000) CellIP = 0;
  25.                         break;
  26.                     case (byte) Command.PREV:
  27.                         CellIP--;
  28.                         if (CellIP == -1) CellIP = 29998;
  29.                         break;
  30.                     case (byte) Command.LOOP_BEG:
  31.                         if(Cells[CellIP] == 0)
  32.                         {
  33.                             while(ByteCode[VmIP] != (byte) Command.LOOP_END)
  34.                             {
  35.                                 VmIP++;
  36.                             }
  37.                         }
  38.                         else
  39.                         {
  40.                             Stack.Push(VmIP);
  41.                         }
  42.                         break;
  43.                     case (byte) Command.LOOP_END:
  44.                         if(Cells[CellIP] != 0)
  45.                         {
  46.                             VmIP = Stack.Peek();
  47.                         }
  48.                         else
  49.                         {
  50.                             Stack.Pop();
  51.                         }
  52.                         break;
  53.                 }
  54.                 VmIP++;
  55.             }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement