Exemple #1
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);
                }
            }
        }
Exemple #2
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;
            }
        }