Ejemplo n.º 1
0
        /// <summary>
        /// Emits the specified platform instruction.
        /// </summary>
        /// <param name="context">The context.</param>
        /// <param name="emitter">The emitter.</param>
        protected override void Emit(Context context, MachineCodeEmitter emitter)
        {
            // TODO: Remove
            if (context.Operand1 is MemberOperand)
                return;
            if (context.Result is RegisterOperand && context.Operand1 is MemoryOperand)
            {
                RegisterOperand result = context.Result as RegisterOperand;
                MemoryOperand operand = context.Operand1 as MemoryOperand;

                int displacement = operand.Offset.ToInt32();

                if (IsBetween(displacement, 0, 14))
                {
                    emitter.EmitDisplacementLoadStoreWithK3Immediate((byte)operand.Base.RegisterCode, (byte)(0x01), (sbyte)(displacement>>1), (byte)result.Register.RegisterCode);
                }
                else
                    if (IsBetween(displacement, -32768, 32767))
                    {
                        emitter.EmitTwoRegistersAndK16(0x11, (byte)operand.Base.RegisterCode, (byte)result.Register.RegisterCode, (short)displacement);
                    }
                    else
                        throw new OverflowException();
            }
            else
                throw new Exception("Not supported combination of operands");
        }