예제 #1
0
            private static bool ComprobarLinea(string texto)
            {
                if (texto[texto.Length - 1] == '\r')
                {
                    texto.Substring(0, texto.Length - 1);
                }

                while (texto.Contains("  "))
                {
                    texto = texto.Replace("  ", " ");
                }

                string[] linea       = texto.Trim().Split(' ');
                string   instruccion = string.Empty;

                if (!UtilidadesInstruccion.esInstruccion(linea[0]))
                {
                    if (Etiqueta(linea[0]))
                    {
                        for (int i = 1; i < linea.Length; i++)
                        {
                            instruccion += linea[i];
                        }
                    }
                    else
                    {
                        return(false);
                    }
                }
                else
                {
                    instruccion = texto;
                }
                return(Instruccion0(instruccion) || Instruccion2(instruccion) || Instruccion1(instruccion));
            }
예제 #2
0
        public void EscribirLinea(ref ushort posicion)
        {
            if (lineas.Count > 0)
            {
                foreach (string[] linea in lineas)
                {
                    //forma fácil: escribir en memoria y en registro de instrucciones al mismo tiempo
                    //Main.AñadirInstruccionRegistroInstrucciones(FInstruccion.ConvertirEnInstruccion(UtilidadesInstruccion.ExtraerInstruccionArgumentos(linea[1])), posicion);

                    ushort pos = posicion;
                    Main.ObtenerMemoria.EscribirInstruccionMemoria(Instruccion.ConvertirEnInstruccion(UtilidadesInstruccion.ExtraerInstruccionArgumentos(linea[1])), ref posicion);
                    Main.AñadirInstruccionListaInstrucciones(UtilidadesInstruccion.DescodificarInstruccion(Main.ObtenerMemoria.ObtenerDireccion(pos).Contenido, pos), pos);
                }
            }
        }
예제 #3
0
            private static void AñadirEtiqueta(string texto)
            {
                if (texto[texto.Length - 1] == '\r')
                {
                    texto.Substring(0, texto.Length - 1);
                }

                while (texto.Contains("  "))
                {
                    texto = texto.Replace("  ", " ");
                }

                string[] linea = texto.Trim().Split(' ');
                if (!UtilidadesInstruccion.esInstruccion(linea[0]) && Etiqueta(linea[0]))
                {
                    etiquetas.Add(linea[0]);
                }
            }
예제 #4
0
        public void LeerLinea(string linea, ref ushort posicion)
        {
            Instruccion instruccion = null;

            string[] instruccionArgumentos = UtilidadesInstruccion.ExtraerInstruccionArgumentos(linea);

            if (UtilidadesInstruccion.esInstruccion(instruccionArgumentos[0]))
            {
                instruccion = Instruccion.ConvertirEnInstruccion(instruccionArgumentos);
                lineas.Add(new string[] { string.Empty, linea });
                //--
                //lineas2.Add(new EtiquetaInstruccion(string.Empty, linea));
            }
            else
            {
                Main.ObtenerMemoria.Etiquetas.Add(new Etiqueta(posicion, instruccionArgumentos[0]));
                if (instruccionArgumentos.Length <= 0)
                {
                    throw new ArgumentException();
                }

                string[] _instruccionArgumentos = new string[instruccionArgumentos.Length - 1];
                for (int i = 0; i < _instruccionArgumentos.Length; i++)
                {
                    _instruccionArgumentos[i] = instruccionArgumentos[i + 1];
                }
                instruccion = Instruccion.ConvertirEnInstruccion(_instruccionArgumentos);
                lineas.Add(new string[] { instruccionArgumentos[0], linea.Substring(instruccionArgumentos[0].Length).TrimStart() });
                //lineas2.Add(new EtiquetaInstruccion(instruccionArgumentos[0], linea.Substring(instruccionArgumentos[0].Length).TrimStart()));
            }

            switch (instruccion.NumArgumentos)
            {
            case 0:
                posicion++;
                break;

            case 1:
                if (instruccion is IInstruccionSalto)
                {
                    posicion += 3;
                }
                else
                {
                    if (instruccion.ObtenerArgumento(0).TipoArgumento() == Argumento.Tipo.Literal)
                    {
                        posicion += 2;
                    }
                    else
                    {
                        posicion++;
                    }
                }
                break;

            case 2:
                if (instruccion.ObtenerArgumento(0).TipoArgumento() == Argumento.Tipo.Literal)
                {
                    posicion += 2;
                }
                else
                {
                    posicion += 3;
                }
                break;
            }
        }