Exemplo n.º 1
0
        /// <summary>
        /// Translates the instruction and sets the Code property.
        /// If an error is detected, Error property is set instead.
        /// </summary>
        /// <returns>A value indicating if the translation was successful</returns>
        public override bool Translate()
        {
            Error = null;
            if (!CheckArgument1())
            {
                return(false);
            }
            Code    = new ushort[2];
            Code[0] = 0xD << 12;             // The first word is always the same (only an OPCode).
            int value;

            Argument1.LookUpValue(Assembler, out value);
            Code[1] = (ushort)value;             // The second word is the address of the subroutine.
            return(true);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Translates the first argument to the machine code.
        /// The resulting value contains the argument encoding in the right
        /// position within the word, and zeroes in locations intended for the
        /// OPCode (mnemonic) and the other argument.
        /// </summary>
        /// <returns>A value containing the translation of the argument</returns>
        protected ushort TranslateArgument1()
        {
            int value;

            Argument1.LookUpValue(Assembler, out value);

            // Write address to the lowest 3 bits
            ushort result = (ushort)value;

            if (Argument1.Type == ArgumentType.Indirect)
            {
                // Indirect addressing is indicated by setting the 4th lowest bit.
                result |= 0x8;
            }
            // Move the argument to the right position : 0000aaaa00000000
            result <<= 8;
            return(result);
        }
Exemplo n.º 3
0
        /// <summary>
        /// Checks if the first argument is valid.
        /// </summary>
        /// <remarks>
        /// The first argument of an I/O instruction must be a symbol
        /// present in the symbol table and its value must be between [0..7].
        /// </remarks>
        /// <returns>A value indicating if Argument1 is valid</returns>
        protected bool CheckArgument1()
        {
            int value;

            if (!Argument1.LookUpValue(Assembler, out value))
            {
                return(false);
            }

            if (value < 0 || value > 7)
            {
                Error             = new Error();
                Error.ID          = 3;
                Error.Description = string.Format(Messages.E0003, Argument1.Text, 0, 7);
                Error.Line        = Line;
                Error.Column      = Argument1.Column;
                return(false);
            }
            return(true);
        }