Created
May 19, 2016 08:45
-
-
Save Nikola-Andreev/e4fd15622e553fcbc74f6ba53f7e7633 to your computer and use it in GitHub Desktop.
Instruction Set
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.Numerics; | |
using System.Globalization; | |
using System.Text.RegularExpressions; | |
namespace Praktice | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
string opCode = string.Empty; | |
decimal result = 0; | |
List<decimal> output = new List<decimal>(); | |
while (opCode != "END") | |
{ | |
if (opCode!=string.Empty) | |
{ | |
string[] codeArgs = opCode.Split(' '); | |
switch (codeArgs[0]) | |
{ | |
case "INC": | |
{ | |
result = decimal.Parse(codeArgs[1]); | |
result++; | |
break; | |
} | |
case "DEC": | |
{ | |
result = decimal.Parse(codeArgs[1]); | |
result--; | |
break; | |
} | |
case "ADD": | |
{ | |
decimal operandOne = decimal.Parse(codeArgs[1]); | |
decimal operandTwo = decimal.Parse(codeArgs[2]); | |
result = operandOne + operandTwo; | |
break; | |
} | |
case "MLA": | |
{ | |
decimal operandOne = decimal.Parse(codeArgs[1]); | |
decimal operandTwo = decimal.Parse(codeArgs[2]); | |
result = operandOne * operandTwo; | |
break; | |
} | |
} | |
output.Add(result); | |
} | |
opCode = Console.ReadLine(); | |
} | |
foreach (var item in output) | |
{ | |
Console.WriteLine(item); | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment