Ejemplo n.º 1
0
        public static Instruction FromDefinition(InstructionDefinition def, Register rs, params int[] args)
        {
            if (args.Length != def.Arguments.Length)
            {
                throw new ArgumentException("Wrong number of arguments.");
            }

            Instruction ins = new Instruction
            {
                OpCode = def.OpCode
            };

            if (def.OpCode == OpCode.Register)
            {
                ins.FunctionCode = def.FunctionCode;
            }
            if (def.OpCode == OpCode.Branch)
            {
                ins.BranchCode = def.BranchCode;
            }

            for (int i = 0; i < def.Arguments.Length; i++)
            {
                switch (def.Arguments[i])
                {
                case InstructionArgumentType.Rd:
                    ins.Rd = args[i];
                    break;

                case InstructionArgumentType.Rs:
                    ins.Rs = args[i];
                    break;

                case InstructionArgumentType.Rt:
                    ins.Rt = args[i];
                    break;

                case InstructionArgumentType.Sa:
                    ins.sa = (byte)args[i];
                    break;

                case InstructionArgumentType.Label:
                case InstructionArgumentType.Immediate:
                    ins.Target    = args[i];
                    ins.Immediate = (ushort)args[i];
                    break;

                case InstructionArgumentType.ImmediateRs:
                    ins.Immediate = (ushort)args[i];
                    ins.Rs        = (int)rs;
                    break;
                }
            }

            return(ins);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Gets the string representation of an instruction.
        /// </summary>
        public static string GetString(Instruction ins)
        {
            if (ins.OriginalInstruction.HasValue && ins.OriginalInstruction.Value == 0)
            {
                return("null");
            }

            // Get the instruction definition for this instruction
            var def = InstructionDefinition.ForInstruction(ins);

            // Join all the arguments together, calling GetArg on each argument.
            var args = string.Join(", ", def.Arguments.Select(arg => GetArg(arg, ins)));

            // Format the instruction.
            return(string.Format("{0} {1}", def.Name, args).Trim());
        }
Ejemplo n.º 3
0
 public override string ToString()
 {
     return(InstructionDefinition.GetString(this));
 }
Ejemplo n.º 4
0
 public static Instruction FromDefinition(InstructionDefinition def, params int[] args)
 {
     return(FromDefinition(def, Register.zero, args));
 }