Beispiel #1
0
        public Instruction(IWordStream stream, ulong address)
        {
            var bits = new BitStream(stream.ReadWord(address++));

            this.Length     = 1;
            this.Code       = bits.ReadU8(8);
            this.Definition = InstructionDefinition.Find(this.Code);

            if (this.Definition.ParameterCount > 0)
            {
                this.Parameter1 = this.DecodeParameter(stream, ref address, bits);
            }
            if (this.Definition.ParameterCount > 1)
            {
                this.Parameter2 = this.DecodeParameter(stream, ref address, bits);
            }
            if (this.Definition.ParameterCount > 2)
            {
                this.Parameter3 = this.DecodeParameter(stream, ref address, bits);
            }

            bits.Advance((3 - this.Definition.ParameterCount) * 8);

            if (bits.ReadU1())
            {
                this.ConditionalZero      = bits.ReadU1();
                this.ConditionalParameter = this.DecodeParameter(stream, ref address, bits);
            }
        }
Beispiel #2
0
        public Instruction(byte code, IList <Parameter> parameters, Parameter conditionalParameter, bool conditionalZero)
        {
            this.Code   = code;
            this.Length = (byte)(1 + (conditionalParameter?.Length ?? 0));
            this.ConditionalParameter = conditionalParameter;
            this.ConditionalZero      = conditionalZero;
            this.Definition           = InstructionDefinition.Find(this.Code);

            if (this.Definition.ParameterCount >= 1)
            {
                this.Parameter1 = parameters[0];
                this.Length    += this.Parameter1.Length;
            }

            if (this.Definition.ParameterCount >= 2)
            {
                this.Parameter2 = parameters[1];
                this.Length    += this.Parameter2.Length;
            }

            if (this.Definition.ParameterCount >= 3)
            {
                this.Parameter3 = parameters[2];
                this.Length    += this.Parameter3.Length;
            }
        }
        static InstructionDefinition()
        {
            InstructionDefinition.mnemonics    = new Dictionary <string, InstructionDefinition>();
            InstructionDefinition.instructions = new InstructionDefinition[256];

            InstructionDefinition.Add("HLT", 0);
            InstructionDefinition.Add("NOP", 1);
            InstructionDefinition.Add("INT", 2, ParameterDirection.Read, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("EINT", 3);
            InstructionDefinition.Add("INTE", 4);
            InstructionDefinition.Add("INTD", 5);
            InstructionDefinition.Add("XCHG", 6, ParameterDirection.Write | ParameterDirection.Read, ParameterDirection.Write | ParameterDirection.Read);
            InstructionDefinition.Add("CAS", 7, ParameterDirection.Write | ParameterDirection.Read, ParameterDirection.Write | ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("SET", 8, ParameterDirection.Write, ParameterDirection.Read);
            InstructionDefinition.Add("CPY", 9, ParameterDirection.Read, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("CALL", 10, ParameterDirection.Read);
            InstructionDefinition.Add("RET", 11);

            InstructionDefinition.Add("ADD", 20, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("ADDF", 21, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("SUB", 22, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("SUBF", 23, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("DIV", 24, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("DIVF", 25, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("MUL", 26, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("MULF", 27, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("MOD", 28, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("MODF", 29, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("ITOF", 30, ParameterDirection.Write, ParameterDirection.Read);
            InstructionDefinition.Add("FTOI", 31, ParameterDirection.Write, ParameterDirection.Read);

            InstructionDefinition.Add("SR", 40, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("SL", 41, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("RR", 42, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("RL", 43, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("NAND", 44, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("AND", 45, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("NOR", 46, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("OR", 47, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("NXOR", 48, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("XOR", 49, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("NOT", 50, ParameterDirection.Write, ParameterDirection.Read);
            InstructionDefinition.Add("GT", 51, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("GTE", 52, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("LT", 53, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("LTE", 54, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("EQ", 55, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);
            InstructionDefinition.Add("NEQ", 56, ParameterDirection.Write, ParameterDirection.Read, ParameterDirection.Read);

            InstructionDefinition.Add("DBG", 60, ParameterDirection.Write | ParameterDirection.Read, ParameterDirection.Write | ParameterDirection.Read, ParameterDirection.Write | ParameterDirection.Read);
            InstructionDefinition.Add("BRK", 61);
        }
 private static void Add(string mnemonic, byte code, ParameterDirection parameter1Direction, ParameterDirection parameter2Direction, ParameterDirection parameter3Direction) => InstructionDefinition.Add(new InstructionDefinition(mnemonic, code, parameter1Direction, parameter2Direction, parameter3Direction));
 private static void Add(string mnemonic, byte code) => InstructionDefinition.Add(new InstructionDefinition(mnemonic, code));
 private static void Add(InstructionDefinition def)
 {
     InstructionDefinition.mnemonics.Add(def.Mnemonic, def);
     InstructionDefinition.instructions[def.Code] = def;
 }