Esempio n. 1
0
        /// <summary>
        /// Tries to parse each delabeled line of code into instruction code and returns the resulting memory array
        /// </summary>
        /// <param name="code">Delabeled code to parse</param>
        /// <param name="instructions">Value to store the result into</param>
        private bool TryParseInstructions(List<string[]> code, ref UNum[] instructions)
        {
            UNum[] temp = new UNum[code.Count];
            for(int i = 0; i < code.Count; i++)
            {
                string[] line = code[i];
                if (line.Length <= 0 || line.Length > 2) { return false; }

                Instruction instruction;
                if (!charCodes.TryGetValue(line[0], out instruction)) { return false; }
                int address = 0;
                if (line.Length == 2 && !int.TryParse(line[1], out address) && address >= 0 && address <= 99) { return false; }
                temp[i] = (int)instruction + address;
            }
            instructions = temp;
            return true;
        }
Esempio n. 2
0
 /// <summary>
 /// Creates a new Label
 /// </summary>
 /// <param name="name">Name of the label</param>
 /// <param name="line">Line number of the label</param>
 public Label(string name, UNum line)
 {
     this.name = name.Remove(name.Length - 1);
     this.line = line;
 }
Esempio n. 3
0
 /// <summary>
 /// Prints the memory number array
 /// </summary>
 /// <param name="instructions">Memory to print</param>
 public static string PrintInstructions(UNum[] instructions)
 {
     return "[ " + String.Join(",\n  ", instructions.Select(i => i.ToString())) + " ]";
 }