Beispiel #1
0
 /// <summary>
 /// Exit a parse tree produced by the <c>InstruccionIndexada</c>
 /// labeled alternative in <see cref="SicAsmParser.inst"/>.
 /// <para>The default implementation does nothing.</para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 public virtual void ExitInstruccionIndexada([NotNull] SicAsmParser.InstruccionIndexadaContext context)
 {
 }
Beispiel #2
0
        public override string VisitInstruccionIndexada([NotNull] SicAsmParser.InstruccionIndexadaContext context)
        {
            string addr_mode  = "I";
            string label      = "----";
            string inst       = "";
            string id         = "";
            int    addr_value = 0;
            int    cp         = _program_counter;
            string opcode;

            inst   = context.opcode.Text;
            opcode = (string)_opcodes[inst];

            if (_first_inst_addr == -1)
            {
                _first_inst_addr = cp;
            }

            switch (context.num_type.Type)
            {
            case SicAsmParser.LABEL:
                id = context.LABEL().GetText();

                /*Si es segunda pasada...*/
                if (!_is_first_pass)
                {
                    if (_symtab.ContainsKey(id))
                    {
                        addr_value = (int)_symtab[id];
                    }
                    else
                    {
                        addr_value = MAX_ADDR;
                        _lines_opcode.Add(_line_count + 1, opcode + addr_value.ToString("X4"));
                        return("Error: símbolo \"" + id + "\" No definido");
                    }
                }

                break;

            case SicAsmParser.HEX:
                string hex_str = context.HEX().GetText().Remove(context.HEX().GetText().Length - 1);
                id         = "" + int.Parse(hex_str, System.Globalization.NumberStyles.HexNumber);
                addr_value = int.Parse(hex_str, System.Globalization.NumberStyles.HexNumber);
                break;

            case SicAsmParser.INT:
                id         = context.INT().GetText();
                addr_value = int.Parse(id);
                break;
            }

            /* Si es la primera pasada */
            if (_is_first_pass)
            {
                _lines_pc.Add(_line_count + 1, _program_counter);
                _program_counter += 3;
            }
            else /* Si es la segunda pasada */
            {
                if (addr_value > MAX_ADDR)
                {
                    addr_value = 0xFFFF;
                    _lines_opcode.Add(_line_count + 1, opcode + addr_value.ToString("X4"));
                    return("Error, dirección fuera de rango, debe ser menor o igual a 0x7FFF");
                }
                addr_value |= 0x8000;
                _lines_opcode.Add(_line_count + 1, opcode + addr_value.ToString("X4"));
            }

            return("PC= " + cp + " LABEL=" + label + " OPCODE=" + inst + " ID=" + id + " M:" + addr_mode);
        }
Beispiel #3
0
 /// <summary>
 /// Visit a parse tree produced by the <c>InstruccionIndexada</c>
 /// labeled alternative in <see cref="SicAsmParser.inst"/>.
 /// <para>
 /// The default implementation returns the result of calling <see cref="AbstractParseTreeVisitor{Result}.VisitChildren(IRuleNode)"/>
 /// on <paramref name="context"/>.
 /// </para>
 /// </summary>
 /// <param name="context">The parse tree.</param>
 /// <return>The visitor result.</return>
 public virtual Result VisitInstruccionIndexada([NotNull] SicAsmParser.InstruccionIndexadaContext context)
 {
     return(VisitChildren(context));
 }