コード例 #1
0
        public DIRECTIVA(String directive,OPERANDO operando,LABEL label)
        {
            baseNumerica base1 = new baseNumerica(operando.getOperando());
            //base1.convert2Dec();
            codigoMaquina = "";
            valida = true;
            size = 0;
            valueHex = "";
            if (!base1.getValido() && directive != "FCC" && directive != "END")
            {
                imprimirMensaje = "[Error]El operando contiene valores que no son validos en su base";
                valida = false;
            }
            if (operando.getOperando() == "NULL" && directive != "END")
            {
                imprimirMensaje = "[Error]La Directiva necesita operando";
                valida = false;
            }
            switch (directive)
            {
                case "ORG":
                    existe = true;
                    if (!(base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 65535))
                    {
                       imprimirMensaje = "[Error]Valor invalido para " + directive + " los valores van de 0-65535";
                       valida = false;
                    }
                    break;
                case "END":
                    existe = true;
                    if(operando.getOperando()!="NULL")
                    {
                        imprimirMensaje = "[Error]END no debe llevar operando";
                        valida = false;
                    }
                    break;
                case "DB":
                case "DC.B":
                case "FCB":
                    existe = true;
                    if (base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 255)
                    {
                        size = 1;
                        try
                        {
                            codigoMaquina = base1.getNumberHexadecimal().PadLeft(2, '0');
                        }
                        catch(Exception ex)
                        {
                            imprimirMensaje = "[Error] Valores invalidos para la base";
                            valida = false;
                        }
                    }
                    else
                    {
                        imprimirMensaje = "[Error]Valor invalido para " + directive + " los valores van de 0-255";
                        valida = false;
                    }
                    break;
                case "DW":
                case "DC.W":
                case "FDB":
                    existe = true;
                    if (base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 65535)
                    {
                        size = 2;
                        try
                        {
                            codigoMaquina = base1.getNumberHexadecimal().PadLeft(4, '0');
                        }
                        catch(Exception ex)
                        {
                            imprimirMensaje = "[Error] Valores invalidos para la base";
                            valida = false;
                        }
                    }
                    else
                    {
                        imprimirMensaje = "[Error]Valor invalido para " + directive + " los valores van de 0-65535";
                        valida = false;
                    }
                    break;
                case "FCC":
                    existe = true;
                    if ((@operando.getOperando()[0] == '"' && @operando.getOperando()[operando.getOperando().Length - 1] == '"') && operando.getOperando().Length >= 2)
                    {
                        size = operando.getOperando().Length - 2;
                        baseNumerica b2 = new baseNumerica("0");
                        for (int i = 1; i<operando.getOriginal().Length-1;i++ )
                        {
                            int tmpIntFCC = 0;
                            tmpIntFCC = System.Convert.ToInt16(operando.getOriginal()[i]);
                            b2 = new baseNumerica(System.Convert.ToString(tmpIntFCC));
                            codigoMaquina += b2.getNumberHexadecimal();
                        }
                    }
                    else
                    {
                        imprimirMensaje = "[Error]El operando no tiene ambas comillas";
                        valida = false;
                    }
                    break;
                case "DS":
                case "DS.B":
                case "RMB":
                    existe = true;
                    if (base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 65535)
                    {
                        size = 1 * base1.getNumberDecimal();
                    }
                    else
                    {
                        imprimirMensaje = "[Error]Valor invalido para " + directive + " los valores van de 0-65535";
                        valida = false;
                    }
                    break;
                case "DS.W":
                case "RMW":
                    existe = true;
                    if (base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 65535)
                    {
                        size = 2 * base1.getNumberDecimal();
                    }
                    else
                    {
                        imprimirMensaje = "[Error]Valor invalido para " + directive + " los valores van de 0-65535";
                        valida = false;
                    }
                    break;
                case "EQU":
                    existe = true;

                    if(label.getLabel() == "NULL")
                    {
                        imprimirMensaje = "[Error]EQU debe tener etiqueta";
                        valida = false;
                    }
                    else if (!(base1.getNumberDecimal() >= 0 && base1.getNumberDecimal() <= 65535))
                    {
                        imprimirMensaje += "[Error]Valor invalido para " + directive + " los valores van de 0-65535";
                        valida = false;
                    }
                    else
                    {
                        baseNumerica b1 = new baseNumerica(operando.getOperando());
                        valueHex = b1.getNumberHexadecimal();
                    }
                    break;
                default:
                    existe = valida = false;
                    break;
            }//End switch
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: irvingnor/Assembler-HCS12
        private void separaCadena(String cadena)
        {
            if (cadena[0] == ';')
            {
                txtMensajes.Text += "Comentario";
                printEnter();
                return;
            }
            //##############################################################################################
            //Separo la cadena con un automata
            String[] separados = new String[3];//[0]Etiqueta [1]CODOP [2]OPERANDO
            bool[] validos = new bool[3];
            int[,] estados = new int[5,2]{
            {0,1},
            {2,1},
            {2,3},
            {4,3},
            {4,4}};
            int state=0,input=0,sizeString=cadena.Length,sizeTotal=0,i=0;
            while(i<sizeString)
            {
                switch(cadena[i])
                {
                    case ' ': case '\t':
                        input = 1;
                        break;
                    default:
                        input = 0;
                        break;
                }
                state = estados[state,input];
                switch(state){
                    case 0:
                        separados[sizeTotal] += cadena[i++];
                        break;

                    case 1:case 3:
                        i++;
                        if (i < sizeString && cadena[i] != ' ' && cadena[i] != '\t')
                        {
                            sizeTotal++;
                        }
                        break;

                    case 2:
                        separados[sizeTotal] += cadena[i++];
                        break;

                    case 4:
                        separados[sizeTotal] += cadena[i++];
                        break;
                }
            }

            for (int j = 0; j < 3; j++)
            {
                if (separados[j] == null)
                    separados[j] = "NULL";
            }
                //##############################################################################################

            //Creo los objetos de las respectivas clases.
            label = new LABEL(separados[0]);
            label.validaEtiqueta();
            codop = new CODOP(separados[1]);
            codop.validaCODOP();
            operando = new OPERANDO(separados[2]);
            operando.validaOperando();

               //Valido las combinaciones
               if (codop.getCodop() == "NULL")
               {
                    txtMensajes.Text += "Linea: " + (lineasArchivo + 1);
                    printEnter();
                    txtMensajes.Text += mensajesError[0];//Dice cuales son las combinaciones validas...
                    printEnter();
                    printEnter();
                    return;
               }

            //Validaciones para la etiqueta
            if (label.getValida())
            {
                txtMensajes.Text += "ETIQUETA = " + label.getLabel();//Etiqueta
                printEnter();
                //Guardo en el tabsim la etiqueta
                if (label.getLabel() != "NULL" && codop.getCodop() != "EQU")
                {
                    Boolean flagEncontrada = false;
                    foreach(String labelTMP in listaEtiquetas)
                    {
                        if(label.getLabel() == labelTMP)
                        {
                            flagEncontrada = true;
                        }
                    }

                    if (!flagEncontrada)
                    {
                        lfile.setLabel(label.getLabel());
                        lfile.setValue(contLoc.getNumberHexadecimal().PadLeft(4, '0'));//Modifica1 Contoloc
                        lfile.save(fsTabsim, 2);
                        listaEtiquetas.Add(label.getLabel());
                        dirEtiquetas.Add(contLoc.getNumberHexadecimal());
                    }
                    else
                    {
                        txtMensajes.Text +=  mensajesError[7];
                    }
                }
                //Prepara para el archivo TMP
                lfile.setLabel1(label.getLabel());
            }
            else
            {
                txtMensajes.Text += "Linea: " + (lineasArchivo + 1);
                printEnter();
                txtMensajes.Text += mensajesError[1];//Etiqueta no valida
                printEnter();
            }

            //Validaciones para el CODOP
            if (codop.getValido())
            {
                txtMensajes.Text += "CODOP = " + codop.getCodop();//Codop
                printEnter();
                binarySearch(0,200,codop.getCodop());
                if (codop.getExiste())
                {
                    codop.revizaModoDireccionamiento(arrayCODOP,arrayTMPCODOP[codop.getIniciaCODOP()].start,arrayTMPCODOP[codop.getIniciaCODOP()].end,operando);
                    //Preparo para guardar en el archivo TMP
                    lfile.setCODOP(codop.getCodop());
                }
                else
                {
                    directive = new DIRECTIVA(codop.getCodop(),operando,label);
                    if (directive.getExiste())
                    {
                        if(directive.getValida())
                        {
                            //Preparo para guardar en el archivo TMP
                            if(codop.getCodop() == "ORG")
                            {
                                baseNumerica b1 = new baseNumerica(System.Convert.ToString(operando.getOperando()));
                                contLoc = b1;
                                dirInicial = b1;
                                //contLoc.setNumberHexadecimal(b1.getNumberHexadecimal());
                            }
                            else if(codop.getCodop() == "EQU")
                            {
                                baseNumerica b1 = new baseNumerica(System.Convert.ToString(operando.getOperando()));

                                Boolean flagExist = false;
                                foreach(String stmp in listaEtiquetas)
                                {
                                    if(stmp == label.getLabel())
                                    {
                                        flagExist = true;
                                    }
                                }

                                if (flagExist)
                                {
                                    txtMensajes.Text += mensajesError[7];
                                    printEnter();
                                }
                                else
                                {
                                    lfile.setLabel(label.getLabel());
                                    //lfile.setValue(directive.getValueHexadecimal());
                                    lfile.setValue(b1.getNumberHexadecimal().PadLeft(4, '0'));//Modifca2 Contloc
                                    lfile.save(fsTabsim, 2);
                                    listaEtiquetas.Add(label.getLabel());
                                    dirEtiquetas.Add(b1.getNumberHexadecimal().PadLeft(4,'0'));
                                    lfile.setValue1(b1.getNumberHexadecimal().PadLeft(4, '0'));
                                }
                            }
                            lfile.setCODOP(codop.getCodop());
                        }
                        else
                        {
                            txtMensajes.Text += directive.getImprimirMensaje();
                            printEnter();
                        }
                    }
                    else
                    {
                        txtMensajes.Text += mensajesError[5];//El CODOP ingresado no existe
                        printEnter();
                    }
                }
            }
            else
            {
                txtMensajes.Text += "Linea: " + (lineasArchivo + 1);
                printEnter();
                txtMensajes.Text += mensajesError[2];//Codop no valido
                printEnter();
            }

            //Validaciones para el OPERANDO
            txtMensajes.Text += "OPERANDO = " + operando.getOperando();//Operando
            printEnter();
            //Preparo para guardar operando
            lfile.setOperando(operando.getOriginal());

            txtMensajes.Text += codop.getMensajeResultado() + "  ";

            if (codop.getBytesTotales() > 0)
            {
                txtMensajes.Text +=  Convert.ToString(codop.getBytesTotales()) + " bytes";
            }
            printEnter();

            //Verifico si el codop necesita un operando
            if (operando.getOperando() == "NULL" && codop.getNecesitaOperando() && codop.getExiste())
            {
                txtMensajes.Text += mensajesError[3];//El codop necesita operando
                printEnter();
            }
            else if(operando.getOperando() != "NULL" && !codop.getNecesitaOperando() && codop.getExiste())
            {
                txtMensajes.Text += mensajesError[4];//El codop no necesita operando
                printEnter();
            }
            printEnter();

            //Verifico si hay un END de cierre
            if (codop.getCodop() == "END") { banderaEnd = true; }

            baseNumerica OV = new baseNumerica(System.Convert.ToString(0));

            //Recalculo el ContLOc
            if (codop.getExiste())
            {
                OV = new baseNumerica(System.Convert.ToString(codop.getBytesTotales()));
            }
            else if(directive.getValida())
            {
                OV = new baseNumerica(System.Convert.ToString(directive.getSize()));
            }

            //int temporal = contLoc.getNumberDecimal() + OV.getNumberDecimal();
            //baseNumerica TMP = new baseNumerica(System.Convert.ToString(temporal));

            //contLoc = TMP;

            if (codop.getCodop() != "EQU")
            {
                lfile.setValue1(contLoc.getNumberHexadecimal().PadLeft(4, '0'));//Modifica3 Contloc
            }
            //Guardo el TMP
            lfile.save(fsTMP,1);

            int temporal = contLoc.getNumberDecimal() + OV.getNumberDecimal();
            baseNumerica TMP = new baseNumerica(System.Convert.ToString(temporal));

            contLoc = TMP;

            //Llamo al destructor
            codop = null;
            GC.Collect();
        }