Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void Run()
- {
- while(ByteCode.Length > VmIP)
- {
- switch (ByteCode[VmIP])
- {
- case (byte) Command.INC:
- Cells[CellIP]++;
- break;
- case (byte) Command.DEC:
- Cells[CellIP]--;
- break;
- case (byte) Command.PRINT:
- Console.Write((char) Cells[CellIP]);
- break;
- case (byte) Command.READ:
- string input = Console.ReadKey(false).KeyChar.ToString();
- byte res = Encoding.ASCII.GetBytes(input)[0];
- if(res == 10) Console.WriteLine();
- Cells[CellIP] = res;
- break;
- case (byte) Command.NEXT:
- CellIP++;
- if (CellIP == 30000) CellIP = 0;
- break;
- case (byte) Command.PREV:
- CellIP--;
- if (CellIP == -1) CellIP = 29998;
- break;
- case (byte) Command.LOOP_BEG:
- if(Cells[CellIP] == 0)
- {
- while(ByteCode[VmIP] != (byte) Command.LOOP_END)
- {
- VmIP++;
- }
- }
- else
- {
- Stack.Push(VmIP);
- }
- break;
- case (byte) Command.LOOP_END:
- if(Cells[CellIP] != 0)
- {
- VmIP = Stack.Peek();
- }
- else
- {
- Stack.Pop();
- }
- break;
- }
- VmIP++;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement