Beispiel #1
0
        public static IValue ParseValue(string text, int sectionCharIndex, ParsingStatus status)
        {
            if (text.Length < 2 || text[0] != '=' || text[text.Length - 1] != '=')
            {
                return(null);
            }

            var expressionValue = WValue.ParseValue(text.Substring(1, text.Length - 2), sectionCharIndex + 1, status);

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

            var literalMagnitude = expressionValue.GetMagnitude(status.LocationCounter);
            var literalSign      = expressionValue.GetSign(status.LocationCounter);

            int count = 0;
            var name  = GetName(literalSign, literalMagnitude, count);

            while (status.Symbols[name] != null)
            {
                count++;
                name = GetName(literalSign, literalMagnitude, count);
            }

            SymbolBase literalConstantSymbol = new LiteralConstantSymbol(literalSign, literalMagnitude, name);

            status.Symbols.Add(literalConstantSymbol);
            return(literalConstantSymbol);
        }
Beispiel #2
0
        /// <summary>
        /// This method is used to handle instructions targeted at the assembler itself.
        /// </summary>
        static bool HandleAssemblyInstruction(string opField, string addressField, SymbolBase symbol, ParsingStatus status)
        {
            IValue expression;

            status.LineSection = LineSection.AddressField;
            switch (opField)
            {
            case "EQU":
                // set value of the instruction symbol (first field) to the value of the expression that is in the address field
                if (symbol != null)
                {
                    expression = WValue.ParseValue(addressField, 0, status);

                    if (!expression.IsValueDefined(status.LocationCounter))
                    {
                        status.ReportParsingError(0, addressField.Length, "expression value is undefined");
                        return(true);
                    }

                    symbol.SetValue(expression.GetSign(status.LocationCounter), expression.GetMagnitude(status.LocationCounter));
                }

                return(true);

            case "ORIG":
                // set the location counter to the value of the expression that is in the address field
                expression = WValue.ParseValue(addressField, 0, status);

                if (!expression.IsValueDefined(status.LocationCounter))
                {
                    status.ReportParsingError(0, addressField.Length, "expression value is undefined");
                    return(true);
                }

                status.LocationCounter = (int)expression.GetValue(status.LocationCounter);

                return(true);

            case "CON":
            case "ALF":
                // these instructions set the value of the memory word at the location counter, which is actually a loader instruction.
                // However, during assembly these memory words must be skipped, which is why we increase the location counter.
                status.LocationCounter++;

                return(true);
            }

            return(false);
        }
        /// <summary>
        /// Creates an instance of this class by parsing the address field of a loader instruction.
        /// </summary>
        /// <param name="instruction">LoaderInstruction to parse the address field for. This method will throw an exception if this parameter is of a different instruction type.</param>
        /// <param name="addressField">The address field to parse.</param>
        /// <param name="status">ParsingStatus object reflecting the current state of the parse process</param>
        /// <returns></returns>
        public static IInstructionParameters ParseAddressField(InstructionBase instruction, string addressField, ParsingStatus status)
        {
            if (!(instruction is LoaderInstruction))
            {
                throw new ArgumentException("instruction must be a LoaderInstruction", nameof(instruction));
            }

            var    loaderInstruction = (LoaderInstruction)instruction;
            IValue address           = loaderInstruction.Alphanumeric ? CharacterConstantValue.ParseValue(addressField, 0, status) : WValue.ParseValue(addressField, 0, status);

            if (address == null)
            {
                status.ReportParsingError(0, addressField.Length, "unable to parse value");
                return(null);
            }

            return(new LoaderInstructionParameters(address, addressField.Length));
        }