/// <summary> /// Method for performing MUL instruction /// </summary> public static bool Multiply(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) { return(false); } Register rA = module.Registers.RA; Register rX = module.Registers.RX; long rAValue = rA.LongValue; long memoryWordValue = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]).LongValue; var result = decimal.Multiply(rAValue, memoryWordValue); rA.Sign = rX.Sign = result.GetSign(); result = result.GetMagnitude(); var rXResultValue = (long)(result % ((long)1 << rX.BitCount)); var rAResultValue = (long)decimal.Truncate(result / ((long)1 << rX.BitCount)); rA.MagnitudeLongValue = rAResultValue; rX.MagnitudeLongValue = rXResultValue; return(true); }
/// <summary> /// Method for performing the STZ instruction /// </summary> public static bool StoreZero(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress != int.MinValue) { var word = new FullWord(); WordField.LoadFromFullWord(instance.FieldSpec, word).ApplyToFullWord(module.Memory[indexedAddress]); } return(true); }
/// <summary> /// Method for performing CMPx instructions /// </summary> public static bool Compare(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) { return(false); } int registerIndex = instance.MixInstruction.Opcode - opcodeBase; Register register = module.Registers[registerIndex]; module.Registers.CompareIndicator = WordField.LoadFromFullWord(instance.FieldSpec, register.FullWordValue).CompareTo(module.Memory[indexedAddress]).ToCompValue(); return(true); }
/// <summary> /// Method for performing DIV instruction /// </summary> public static bool Divide(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) { return(false); } long memoryWordValue = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]).LongValue; if (memoryWordValue == 0L) { module.ReportOverflow(); return(true); } Register rA = module.Registers.RA; Register rX = module.Registers.RX; long rAValue = rA.LongValue; long rXValue = rX.LongValue; decimal rAXValue = (decimal)rAValue * ((long)1 << rX.BitCount) + rXValue; decimal divider = rAXValue / memoryWordValue; rX.Sign = rA.Sign; rA.Sign = divider.GetSign(); divider = divider.GetMagnitude(); if (divider > rA.MaxMagnitude) { module.ReportOverflow(); return(true); } decimal remainder = rAXValue % memoryWordValue; rA.MagnitudeLongValue = (long)divider; rX.MagnitudeLongValue = (long)remainder; return(true); }
static bool DoLoad(ModuleBase module, MixInstruction.Instance instance, int registerIndex, bool negateSign) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) { return(false); } var memoryField = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]); if (negateSign) { memoryField.InvertSign(); } memoryField.ApplyToRegister(module.Registers[registerIndex]); return(true); }
/// <summary> /// Method for performing ADD and SUB instructions /// </summary> public static bool AddSubstract(ModuleBase module, MixInstruction.Instance instance) { var indexedAddress = InstructionHelpers.GetValidIndexedAddress(module, instance.AddressValue, instance.Index); if (indexedAddress == int.MinValue) { return(false); } Register rA = module.Registers.RA; long rALongValue = rA.LongValue; long memoryWordValue = WordField.LoadFromFullWord(instance.FieldSpec, module.Memory[indexedAddress]).LongValue; if (instance.MixInstruction.Opcode == substractOpcode) { memoryWordValue = -memoryWordValue; } long sumValue = rALongValue + memoryWordValue; if (sumValue != 0L) { rA.Sign = sumValue.GetSign(); sumValue = sumValue.GetMagnitude(); } if (sumValue > rA.MaxMagnitude) { module.ReportOverflow(); sumValue &= rA.MaxMagnitude; } rA.MagnitudeLongValue = sumValue; return(true); }