Пример #1
0
        private void Parse()
        {
            string[] components = SourceAsm.Split((char[])null, StringSplitOptions.RemoveEmptyEntries);
            if (components.Length == 0 || components.Length > 3)
            {
                throw new Exception(String.Format("ERROR: Line {0} : Too many arguments", LineNumber));
            }

            // Parse the op code and 2 params
            Instruction = new Instruction(LineNumber, components[0]);


            // If params are passed a null string to parse they will default to 'unused' type and value of zero
            string lParam = (components.Length >= 2) ? components[1] : null;
            string rParam = (components.Length == 3) ? components[2] : null;


            // Bit of a hack for jump instructions
            // JMP has one param but the parm has to be forced into the 8 bit rparam
            if (Instruction._OpCode == OpCode.JMP ||
                Instruction._OpCode == OpCode.JE ||
                Instruction._OpCode == OpCode.JNE ||
                Instruction._OpCode == OpCode.JZ ||
                Instruction._OpCode == OpCode.JNZ ||
                Instruction._OpCode == OpCode.CMP)
            {
                rParam = lParam;
                lParam = null;
            }

            LeftParam  = new InstructionParameter(LineNumber, lParam);
            RightParam = new InstructionParameter(LineNumber, rParam);

            Validate();
        }