Esempio n. 1
0
        /// <summary>
        /// Create a MIX instruction instance with the parameters contained in this object.
        /// </summary>
        /// <param name="instruction">MixInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param>
        /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param>
        /// <returns></returns>
        public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status)
        {
            if (!(instruction is MixInstruction))
            {
                throw new ArgumentException("instruction must be a MixInstruction", nameof(instruction));
            }

            var mixInstruction = (MixInstruction)instruction;

            if (!AreValuesDefined(status))
            {
                return(null);
            }

            var addressMagnitude = mAddress.GetMagnitude(status.LocationCounter);
            var word             = new Word(MixInstruction.AddressByteCount);

            if (addressMagnitude > word.MaxMagnitude)
            {
                status.ReportError(LineSection.AddressField, 0, mIndexPartCharIndex, new MixAssembler.Finding.ParsingError("address value " + addressMagnitude + " invalid", (int)-word.MaxMagnitude, (int)word.MaxMagnitude));
                return(null);
            }

            word.MagnitudeLongValue = addressMagnitude;
            var fieldSpecValue = GetFieldSpecValue(status, mixInstruction);

            if (fieldSpecValue == null)
            {
                return(null);
            }

            var instructionWord = new FullWord
            {
                Sign = mAddress.GetSign(status.LocationCounter)
            };

            for (int i = 0; i < word.ByteCount; i++)
            {
                instructionWord[i] = word[i];
            }

            instructionWord[MixInstruction.IndexByte]     = (int)mIndex.GetValue(status.LocationCounter);
            instructionWord[MixInstruction.FieldSpecByte] = fieldSpecValue;
            instructionWord[MixInstruction.OpcodeByte]    = mixInstruction.Opcode;

            var instance = mixInstruction.CreateInstance(instructionWord);

            ReportInstanceErrors(status, instance);

            return(instance);
        }
        /// <summary>
        /// Create a loader instruction instance with the parameters contained in this object.
        /// </summary>
        /// <param name="instruction">LoaderInstruction to create an instance of. This method will throw an exception if this parameter is of a different instruction type.</param>
        /// <param name="status">AssemblingStatus object reflecting the current state of the assembly process</param>
        /// <returns></returns>
        public InstructionInstanceBase CreateInstance(InstructionBase instruction, AssemblingStatus status)
        {
            if (!(instruction is LoaderInstruction))
            {
                throw new ArgumentException("instruction must be a LoaderInstruction", nameof(instruction));
            }

            var loaderInstruction = (LoaderInstruction)instruction;

            if (!mValue.IsValueDefined(status.LocationCounter))
            {
                status.ReportParsingError(LineSection.AddressField, 0, mTextLength, "value is not defined");
                return(null);
            }

            return(new LoaderInstruction.Instance(loaderInstruction, mValue.GetSign(status.LocationCounter), mValue.GetMagnitude(status.LocationCounter)));
        }