コード例 #1
0
        // function for finding the type of instruction
        static string check_type(string op, ref RTdecoder rtd, ref ITdecoder itd, ref JTdecoder jtd)
        {
            // checking if the instruction is R type
            foreach (KeyValuePair <string, string> item in rtd.instructions)
            {
                if (op == item.Key)
                {
                    return("r");
                }
            }

            // checking if the instruction is I type
            foreach (KeyValuePair <string, string> item in itd.instructions)
            {
                if (op == item.Key)
                {
                    return("i");
                }
            }

            // checking if the instruction is J type
            foreach (KeyValuePair <string, string> item in jtd.instructions)
            {
                if (op == item.Key)
                {
                    return("j");
                }
            }
            // what about directives? how to find out them?
            return("");
        }
コード例 #2
0
        public string[] decode(string line)
        {
            RTdecoder rtd = new RTdecoder();
            ITdecoder itd = new ITdecoder();
            JTdecoder jtd = new JTdecoder();

            string[] fields = new string[6];

            if (line.Contains("D"))
            {
                fields = directive_calc(line);
            }
            else
            {
                string type = check_type(line.Substring(4, 4), ref rtd, ref itd, ref jtd);

                if (type == "r")
                {
                    fields = rtd.calc(line);
                }
                else if (type == "i")
                {
                    fields = itd.clac(line);
                }
                else if (type == "j")
                {
                    fields = jtd.calc(line);
                }
            }

            return(fields);
        }