Beispiel #1
0
 private void print(int addr, ValuePart val) //print each cell from address to address
 {
     switch (outputMode)
     {
         case OutputMode.ASCII:
             for (int i = addr; i <= val.Address; i++)
             {
                 Console.Write((char)tape[i]);
             }
             break;
         case OutputMode.Decimal:
             for (int i = addr; i <= val.Address; i++)
             {
                 if (i > addr)
                     Console.Write("-");
                 Console.Write(tape[i]);
             }
             break;
         case OutputMode.Hex:
             for (int i = addr; i <= val.Address; i++)
             {
                 if (i > addr)
                     Console.Write("-");
                 Console.Write(tape[i].ToString("X2"));
             }
             break;
     }
     
 }
Beispiel #2
0
        private ExitStatus exit(ValuePart val) //attempt to return known exit status by value, else return unknown
        {
            ExitStatus status = ExitStatus.Unknown;
            if (Enum.IsDefined(typeof(ExitStatus), val.Value))
                status = (ExitStatus)val.Value;

            return status;
        }
Beispiel #3
0
 private void set(int addr, ValuePart val) //set cell at address on tape to value
 {
     tape[addr] = (byte)val.Value;
 }
Beispiel #4
0
 private void div(int addr, ValuePart val) //divides the value at the given address on the tape by val
 {
     tape[addr] /= (byte)val.Value;
 }
Beispiel #5
0
 private void mod(int addr, ValuePart val) //sets the value at the given address on the tape to the mod of that value and val
 {
     tape[addr] %= (byte)val.Value;
 }
Beispiel #6
0
 private void mul(int addr, ValuePart val) //multiplies the value at the given address on the tape by val
 {
     tape[addr] *= (byte)val.Value;
 }
Beispiel #7
0
 private void sub(int addr, ValuePart val) //subtracts val from the value at given address on the tape
 {
     tape[addr] -= (byte)val.Value;
 }
Beispiel #8
0
 private void add(int addr, ValuePart val) //adds val to the value at given address on the tape
 {
     tape[addr] += (byte)val.Value;
 }
Beispiel #9
0
 private void lookahead(ValuePart val) //looks forward and begins execution at a flag with the same value (greedy)
 {
     for (; currentStatement < statements.Length; currentStatement++)
     {
         if ((Instruction)Convert.ToInt32(statements[currentStatement].Substring(0, 1), 16) == Instruction.Label
             && getValuePart(statements[currentStatement]).Value == val.Value) //if statement is a label and value part is equal to lookahead value
             return;
     }
 }
Beispiel #10
0
        private void input(int addr, ValuePart val) //get text input starting at addr, setting val cell to input end address
        {
            string input = Console.ReadLine();

            int num;
            if (int.TryParse(input, out num) && num < 256) //if input is just a number less than 256, set addr to that number
            {
                tape[addr] = (byte)num;
                tape[val.Address] = 0x01;
                return;
            }

            int i;
            for (i = 0; i < input.Length; i++)
            {
                tape[i + addr] = (byte)input[i];
            }

            tape[val.Address] = (byte)(i + addr);
        }