Example #1
0
 public void checkNedOperando(CODOP[] arrayCODOP, int x1,int x2)
 {
     if (arrayCODOP[x1].getNecesitaOperando())
     {
         this.necesitaOperando = true;
     }
 }
Example #2
0
 public void checkTam(CODOP[] arrayCODOP,int x1, int x2, String modo)
 {
     bool found = false;
     for (; x1 < x2 && !found; x1++)
     {
         if (Convert.ToString(arrayCODOP[x1].getModoDireccionamiento()) == modoDireccionamiento)
         {
             bytesTotales = arrayCODOP[x1].getBytesTotales();
             this.codigoMaquina = arrayCODOP[x1].getCodigoMaquina();
             this.bytesPorCalcular = arrayCODOP[x1].getBytesPorCalcular();
             this.bytesCalculados = arrayCODOP[x1].getBytesCalculados();
             found = true;
         }
     }
 }
Example #3
0
        public void generaCodigoMaquina(baseNumerica contlocFile,CODOP codop,String contLocLabel)
        {
            baseNumerica contEtiqueta = new baseNumerica(contLocLabel);
            baseNumerica contLocNext = new baseNumerica(System.Convert.ToString(contlocFile.getNumberDecimal() + codop.getBytesTotales()));
            baseNumerica contLocNew = new baseNumerica("0");
            fueraRango = false;

            int valor = contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal();

            if (valor < 0)
            {
                char[] caracteres = { '-' };
                String tmp = System.Convert.ToString(valor);
                tmp = tmp.TrimStart(caracteres);
                contLocNew = new baseNumerica(tmp,1);
                tmp = contLocNew.getNumberHexadecimal();
                xb = "";
                for (int i = (tmp.Length) - (2*codop.getBytesPorCalcular()); i<tmp.Length;i++ )
                {
                    xb += tmp[i];
                }
            }
            else
            {
                contLocNew = new baseNumerica(System.Convert.ToString(contEtiqueta.getNumberDecimal() - contLocNext.getNumberDecimal()));
                xb = contLocNew.getNumberHexadecimal();
                xb = xb.PadLeft(2 * codop.getBytesPorCalcular(), '0');
            }
            if(codop.getBytesPorCalcular() == 1)
            {
                if (!(contLocNew.getNumberDecimal() >= -128 && contLocNew.getNumberDecimal() <= 127))
                {
                    fueraRango = true;
                }
            }
            else
            {
                if (!(contLocNew.getNumberDecimal() >= -32768 && contLocNew.getNumberDecimal() <= 32767))
                {
                    fueraRango = true;
                }
            }
        }
Example #4
0
        public void generaXB(CODOP codop)
        {
            String xb1="", xb2="",s1="",s2="";
            tam = operando.Length;
            int i;
            for (i = 0; i < tam && operando[i]!=',';i++ )
            {
                s1 += operando[i];
            }
            for (i+=1; i < tam; i++)
            {
                s2 += operando[i];
            }
            xb1 = "%";
            xb2 = "%";
            Boolean band = false;
            baseNumerica b1 = new baseNumerica("0");
            switch(codop.getModoDireccionamiento())
            {
                case "IDX":
                    baseNumerica b2 = new baseNumerica("0") ,b3 = new baseNumerica("0");
                    if(s2[0]=='+' || s2[0] == '-' || s2[s2.Length-1] == '+' || s2[s2.Length-1] == '-')
                    {
                        xb += "";
                        String tmpReg = "";
                        for (int j = 0; j<s2.Length;j++ )
                        {
                            if(s2[j] != '+' && s2[j] != '-')
                            {
                                tmpReg += s2[j];
                            }
                        }
                        switch(tmpReg)
                        {
                            case "X":
                                xb1 += "001";
                                break;
                            case "Y":
                                xb1 += "011";
                                break;
                            case "SP":
                                xb1 += "101";
                                break;
                            case "PC":
                                xb1 += "111";
                                break;
                        }
                        Boolean flagSigno = false;
                        if(s2[0]=='+')
                        {
                            xb1 += "0";
                        }
                        else if(s2[0]=='-')
                        {
                            xb1 += "0";
                            flagSigno = true;
                        }
                        else if(s2[s2.Length-1] == '+')
                        {
                            xb1 += "1";
                        }
                        else if(s2[s2.Length-1]=='-')
                        {
                            xb1 += "1";
                            flagSigno = true;
                        }

                        if (flagSigno)
                        {
                            switch(s1)
                            {
                                case "1":
                                    xb2 += "1111";
                                    break;
                                case "2":
                                    xb2 += "1110";
                                    break;
                                case "3":
                                    xb2 += "1101";
                                    break;
                                case "4":
                                    xb2 += "1100";
                                    break;
                                case "5":
                                    xb2 += "1011";
                                    break;
                                case "6":
                                    xb2 += "1010";
                                    break;
                                case "7":
                                    xb2 += "1001";
                                    break;
                                case "8":
                                    xb2 += "1000";
                                    break;
                            }//Termina switch
                        }//Termina parte cuando es negativo
                        else
                        {
                            switch (s1)
                            {
                                case "1":
                                    xb2 += "0000";
                                    break;
                                case "2":
                                    xb2 += "0001";
                                    break;
                                case "3":
                                    xb2 += "0010";
                                    break;
                                case "4":
                                    xb2 += "0011";
                                    break;
                                case "5":
                                    xb2 += "0100";
                                    break;
                                case "6":
                                    xb2 += "0101";
                                    break;
                                case "7":
                                    xb2 += "0110";
                                    break;
                                case "8":
                                    xb2 += "0111";
                                    break;
                            }
                        }//Termina cuando es positivo
                        b2 = new baseNumerica(xb1);
                        b3 = new baseNumerica(xb2);
                    }//Termina Indizado pre/post
                    else if(s1[0]=='A' || s1[0]=='B' || s1[0]=='D')
                    {
                        xb1 += "111";
                        switch(s2)
                        {
                            case "X":
                                xb1 += "0";
                                xb2 += "01";
                                break;
                            case "Y":
                                xb1 += "0";
                                xb2 += "11";
                                break;
                            case "SP":
                                xb1 += "1";
                                xb2 += "01";
                                break;
                            case "PC":
                                xb1 += "1";
                                xb2 += "11";
                                break;
                        }
                        switch(s1)
                        {
                            case "A":
                                xb2 += "00";
                                break;
                            case "B":
                                xb2 += "01";
                                break;
                            case "D":
                                xb2 += "10";
                                break;
                        }
                        b2 = new baseNumerica(xb1);
                        b3 = new baseNumerica(xb2);
                    }
                    else//Indizado 5 Bits
                    {
                    switch(s2)
                    {
                        case "X":
                            xb1 += "00";
                        break;
                        case "Y":
                            xb1 += "01";
                        break;
                        case "SP":
                            xb1 += "10";
                        break;
                        case "PC":
                            xb1 += "11";
                        break;
                    }
                    xb1 = xb1 + "0";

                    band = false;
                    b1 = new baseNumerica("0");
                    if(s1=="")
                    {
                        s1 = "0";
                    }

                    if(s1[0]=='-')
                    {
                        char[] caracteres = {'-'};
                        s1 = s1.TrimStart(caracteres);
                        b1 = new baseNumerica(s1,1);
                        band = true;
                    }
                    else
                    {
                        b1 = new baseNumerica(s1);
                    }

                    String tmp="";
                    if(band)
                    {
                        String tmp2 = b1.getNumberBinary();
                        int tamTMP = tmp2.Length;
                        //for (int j = tamTMP -  1; j >= tamTMP - 4; j--)
                        for (int j = tamTMP - 4; j < tamTMP; j++)
                        {
                            tmp += tmp2[j];
                        }
                        xb1 += tmp2[tamTMP - 5];
                        for (int j = 0; j < tmp.Length; j++)
                        {
                            xb2 += tmp[j];
                        }
                    }
                    else
                    {
                        tmp = b1.getNumberBinary().PadLeft(5, '0');
                        xb1 += tmp[0];
                        for (int j = 1; j < tmp.Length; j++)
                        {
                            xb2 += tmp[j];
                        }
                    }

                    b2 = new baseNumerica(xb1);
                    b3 = new baseNumerica(xb2);
                    }//Termina Indizado 5 bits

                    xb = b2.getNumberHexadecimal() + b3.getNumberHexadecimal();
                    break;//Termina IDX
                case "IDX1":
                    band = false;
                    if (s1[0] == '-')
                    {
                        char[] caracteres = { '-' };
                        s1 = s1.TrimStart(caracteres);
                        b1 = new baseNumerica(s1, 1);
                        band = true;
                    }
                    else
                    {
                        b1 = new baseNumerica(s1);
                    }
                    xb1 += "111";
                    switch(s2)
                    {
                        case "X":
                            xb1 += "0";
                            xb2 += "000";
                            break;
                        case "Y":
                            xb1 += "0";
                            xb2 += "100";
                            break;
                        case "SP":
                            xb1 += "1";
                            xb2 += "000";
                            break;
                        case "PC":
                            xb1 += "1";
                            xb2 += "100";
                            break;
                    }
                    String xb3 = "";
                    if (band)
                    {
                        xb2 += "1";
                        int sizeTMP = b1.getNumberHexadecimal().Length;
                        for (int j = sizeTMP - 2 ; j < sizeTMP;j++ )
                        {
                            xb3 += b1.getNumberHexadecimal()[j];
                        }
                    }
                    else
                    {
                        xb2 += "0";
                        xb3 = b1.getNumberHexadecimal().PadLeft(2, '0');
                    }
                    b2 = new baseNumerica(xb1);
                    b3 = new baseNumerica(xb2);
                    xb = b2.getNumberHexadecimal() + b3.getNumberHexadecimal() + xb3;
                    break;
                case "IDX2":
                    band = false;
                    if (s1[0] == '-')
                    {
                        char[] caracteres = { '-' };
                        s1 = s1.TrimStart(caracteres);
                        b1 = new baseNumerica(s1, 1);
                        band = true;
                    }
                    else
                    {
                        b1 = new baseNumerica(s1);
                    }
                    xb1 += "111";
                    switch(s2)
                    {
                        case "X":
                            xb1 += "0";
                            xb2 += "001";
                            break;
                        case "Y":
                            xb1 += "0";
                            xb2 += "101";
                            break;
                        case "SP":
                            xb1 += "1";
                            xb2 += "001";
                            break;
                        case "PC":
                            xb1 += "1";
                            xb2 += "101";
                            break;
                    }
                    xb3 = "";
                    if (band)
                    {
                        xb2 += "1";
                        int sizeTMP = b1.getNumberHexadecimal().Length;
                        for (int j = sizeTMP - 4 ; j < sizeTMP;j++ )
                        {
                            xb3 += b1.getNumberHexadecimal()[j];
                        }
                    }
                    else
                    {
                        xb2 += "0";
                        xb3 = b1.getNumberHexadecimal().PadLeft(4, '0');
                    }
                    b2 = new baseNumerica(xb1);
                    b3 = new baseNumerica(xb2);
                    xb = b2.getNumberHexadecimal() + b3.getNumberHexadecimal() + xb3;
                    break;
            }
        }
Example #5
0
 public void revizaModoDireccionamiento(CODOP[] arrayCODOP, int x1, int x2, OPERANDO operando)
 {
     checkNedOperando(arrayCODOP,x1,x2);
     for (int i = 0; i<flags.Length;i++ )
     {
         flags[0] = false;
     }
     int Tmpx1 = x1;
     for (int i = 0; i < operando.getSize(); i++)
     {
         if (operando.getOperando()[i] == ',')
         {
             flags[0] = true;
         }
         else if (operando.getOperando()[i] == '[' || operando.getOperando()[i] == ']')
         {
             flags[1] = true;
         }
         else if (operando.getOperando()[i] == '+' && flags[0])
         {
             flags[2] = true;
             flags[3] = true;
         }
         else if (operando.getOperando()[i] == '-' && flags[0])
         {
             flags[4] = true;
             flags[2] = true;
         }
         else if (operando.getOperando()[i] == '#')
         {
             flags[6] = true;
         }
         else if(operando.getOperando()[i] >= 'A' && operando.getOperando()[i] <= 'Z' && flags[0])
         {
             flags[7] = true;
         }
     }
     //existe = false;
     for (; x1 < x2 && !flags[5] && !encontrado; x1++)
     {
         //flags[2] = necesitaOperando;
         //string modoDireccionamiento = Convert.ToString(arrayCODOP[x1].getModoDireccionamiento());
         try
         {
             if (!encontrado)
             {
                 flags[2] = necesitaOperando;
                 string modoDireccionamiento = Convert.ToString(arrayCODOP[x1].getModoDireccionamiento());
                 switch (modoDireccionamiento)
                 {
                     case "INH":
                         if (!flags[0])
                             validaInh(operando.getOperando());
                         break;
                     case "IMM":
                         if (!flags[0])
                             validaInm(operando.getOperando());
                         break;
                     case "DIR":
                     case "EXT":
                         if (!flags[0])
                             validaDir(operando.getOperando());
                         break;
                     case "REL":
                         if (!flags[0])
                             validaRel(operando.getOperando());
                         break;
                     case "IDX":
                     case "IDX1":
                     case "IDX2":
                     case "[IDX2]":
                     case "[D,IDX]":
                         validaIdx(operando.getOperando());
                         break;
                 }//Finaliza switch
                 //checkTam(arrayCODOP, Tmpx1, x2, modoDireccionamiento);
             }//Fin de la condicional para saber si ya se encontro
             //else
             //{
             //    checkTam(arrayCODOP, Tmpx1, x2, modoDireccionamiento);
             //}
         }//Fin del try
         catch (Exception ex)
         {
             mensajeResultado = "[Error] El operando no esta completo";
             flags[5] = false;
         }
     }//Fin bucle for
     if (!encontrado)
     {
         Boolean flagSigno = flags[3] || flags[4];
         if ((operando.getOperando()[0] == 'A' || operando.getOperando()[0] == 'B' || operando.getOperando()[0] == 'D') && flags[0])
         {
             mensajeResultado = "[Error] Al validar Indizado de acumulador, las reglas son (A|B|D) seguido de (,) y seguido de (X|Y|SP|PC)";
         }
         else if ((flags[7] && flagSigno) || flagSigno)
         {
             mensajeResultado = "[Error] Al validar pre/post incremento/decremento, las reglas son valores del 1 al 8 una (,) y seguido de un + o - con algun registro como X,Y o SP o bien un registro ed los anteriores seguido de un + o -";
         }
         else if ((flagSigno && flags[0]))
         {
             mensajeResultado = "[Error] Al validar Indexado, las reglas son valores del -16 al 65535 una (,) y seguido de un registro valido(X,Y,SP,PC) ";
         }
         else if (flags[1])
         {
             mensajeResultado = "[Error] Al validar Indexado indirecto o indexado de acumulador indirecto";
         }
         else if (flags[6])
         {
             mensajeResultado = "[Error] Al validar Inmediato. Sintaxis: #(%|@|$ o niguna base) seguido de un numero valido para la base, el rango de valores es 0 a 65535";
         }
         else if (flags[0])
         {
             //Validar caso especial de Indexado
             if (operando.getOperando()[0] == ',' && operando.getOperando().Length > 1 && operando.getOperando().Length <= 3)
             {
                 if (operando.getOperando().Length == 2)
                 {
                     if ((operando.getOperando()[1] == 'X' || operando.getOperando()[1] == 'Y'))
                     {
                         //Caso especial del indizado de 5 bits
                         mensajeResultado = "Indizado de 5 bits";
                         modoDireccionamiento = "IDX";
                         bytesTotales = 2;
                         codigoMaquina = "A6";
                         encontrado = true;
                     }
                     else
                     {
                         mensajeResultado = "[Error] Al validar Indexado, las reglas son valores del -16 al 65535 una (,) y seguido de un registro valido(X,Y,SP,PC) ";
                     }
                 }
                 else
                 {
                     if (((operando.getOperando()[1] == 'S' && operando.getOperando()[2] == 'P') || (operando.getOperando()[1] == 'P' && operando.getOperando()[2] == 'C')))
                     {
                         //Caso especial del indizado de 5 bits
                         mensajeResultado = "Indizado de 5 bits";
                         modoDireccionamiento = "IDX";
                         bytesTotales = 2;
                         codigoMaquina = "A6";
                     }
                     else
                     {
                         mensajeResultado = "[Error] Al validar Indexado, las reglas son valores del -16 al 65535 una (,) y seguido de un registro valido(X,Y,SP,PC) ";
                     }
                 }
             }
             else
             {
                 mensajeResultado = "[Error] Al validar Indexado, las reglas son valores del -16 al 65535 una (,) y seguido de un registro valido(X,Y,SP,PC) ";
             }
         }
     }
     else
     {
         checkTam(arrayCODOP, Tmpx1, x2, modoDireccionamiento);
     }
 }
Example #6
0
        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();
        }
Example #7
0
        private void segundoPaso(String cadena)
        {
            String codigoMaquina = "";
            int tam = cadena.Length;
            String[] arrayLine = new String[4];
            int i = 0,j=0;
            while (i<tam)
            {
                if (cadena[i] != '\t')
                {
                    arrayLine[j] += cadena[i++];
                }
                else
                {
                    j++;
                    i++;
                }
            }
            //Cargo las 4 partes de la linea
            baseNumerica contLocFile = new baseNumerica("$"+arrayLine[0]);
            LABEL labelFile = new LABEL(arrayLine[1]);
            codop = new CODOP(arrayLine[2]);
            OPERANDO operandoFile = new OPERANDO(arrayLine[3]);

            labelFile.validaEtiqueta();
            codop.validaCODOP();
            operandoFile.validaOperando();

            if(codop.getCodop()=="END")
            {
                return;
            }

            if (codop.getValido())
            {
                binarySearch(0, 200, codop.getCodop());
                codop.revizaModoDireccionamiento(arrayCODOP, arrayTMPCODOP[codop.getIniciaCODOP()].start, arrayTMPCODOP[codop.getIniciaCODOP()].end, operandoFile);
            }
            else
            {
                txtMensajes.Text += mensajesError[2];//El CODOP no es valido
                printEnter();
                return;
            }

            if(!codop.getExiste())
            {
                DIRECTIVA d1 = new DIRECTIVA(codop.getCodop(),operandoFile,labelFile);

                if (d1.getExiste() && d1.getValida())
                {
                    txtMensajes.Text += d1.getCodigoMaquina();//11111111111111111111111Imprimo codigo Maquina de la directiva
                    codigoMaquina = d1.getCodigoMaquina();
                    if(codigoMaquina != "")
                    {
                        arrayCodMaqinaS1.Add(codigoMaquina);
                        arrayDirS1.Add(contLocFile);
                    }
                }
                else
                {
                    txtMensajes.Text += mensajesError[6];//No se encontro
                }
                printEnter();
                return;
            }
            //Verifico que tipo de direccionamiento tiene y hago creo el codigo maquina en base a eso
            String xb = "";
            switch(codop.getModoDireccionamiento())
            {
                case "INH":
                    txtMensajes.Text += codop.getCodigoMaquina();//22222222222222222222Imprimo codigo Maquina de codop
                    codigoMaquina = codop.getCodigoMaquina();
                    break;
                case "DIR":
                case "EXT":
                    baseNumerica b1 = new baseNumerica("0");
                    if(operandoFile.getOperando()[0] >= 'A' && operandoFile.getOperando()[0] <= 'Z')
                    {
                        int ilabel = 0,indiceLabel = 0;
                        Boolean labelFound = false;
                        foreach(String lTMP in listaEtiquetas)
                        {
                            if(lTMP == operandoFile.getOriginal())
                            {
                                indiceLabel = ilabel;
                                labelFound = true;
                            }
                            ilabel++;
                        }

                        if(labelFound)
                        {
                            ilabel = 0;
                            String labelExtendido = "";
                            foreach(String lTMP in dirEtiquetas)
                            {
                                if(ilabel == indiceLabel)
                                {
                                    labelExtendido = lTMP;
                                }
                                ilabel++;
                            }//Finaliza bucle foreach
                            labelExtendido = "$" + labelExtendido;
                            b1 = new baseNumerica(labelExtendido);//333333333333Imprimo codigo maquina de codop
                            txtMensajes.Text += codop.getCodigoMaquina() + System.Convert.ToString(b1.getNumberHexadecimal()).PadLeft(2 * codop.getBytesPorCalcular(), '0');
                            codigoMaquina = codop.getCodigoMaquina() + System.Convert.ToString(b1.getNumberHexadecimal()).PadLeft(2 * codop.getBytesPorCalcular(), '0');
                        }
                        else
                        {
                            txtMensajes.Text += mensajesError[8]; //Etiqueta no encontrada
                        }
                    }//Termina cuando es extendido con Etiqueta
                    else
                    {
                        b1 = new baseNumerica(arrayLine[3]);//444444444444444444444444Imprimo codigo maquina de codop
                        txtMensajes.Text += codop.getCodigoMaquina() + System.Convert.ToString(b1.getNumberHexadecimal()).PadLeft(2*codop.getBytesPorCalcular(),'0');
                        codigoMaquina = codop.getCodigoMaquina() + System.Convert.ToString(b1.getNumberHexadecimal()).PadLeft(2 * codop.getBytesPorCalcular(), '0');
                    }
                    break;
                case "IMM":
                    char[] car = {'#'};
                    arrayLine[3] = arrayLine[3].TrimStart(car);
                    baseNumerica b2 = new baseNumerica(arrayLine[3]);//55555555555555555555Imprimo codigo maquina de codop
                    txtMensajes.Text += codop.getCodigoMaquina() + System.Convert.ToString(b2.getNumberHexadecimal()).PadLeft(2 * codop.getBytesPorCalcular(), '0');
                    codigoMaquina = codop.getCodigoMaquina() + System.Convert.ToString(b2.getNumberHexadecimal()).PadLeft(2 * codop.getBytesPorCalcular(), '0');
                    break;
                case "[IDX2]":
                    int sizeTMP = arrayLine[3].Length - 1;
                    String registro = "", operandoTMP = "";
                    Boolean band1 = false;
                    for (i=1; i < sizeTMP ;i++ )
                    {
                        if (arrayLine[3][i]==',')
                        {
                            band1 = true;
                        }
                        else if(!band1)
                        {
                            operandoTMP += arrayLine[3][i];
                        }
                        else
                        {
                            registro += arrayLine[3][i];
                        }
                    }//Fin del for
                    switch(registro)
                    {
                        case "X":
                            xb = "E3";
                            break;
                        case "Y":
                            xb = "EB";
                            break;
                        case "SP":
                            xb = "F3";
                            break;
                        case "PC":
                            xb = "FB";
                            break;
                    }
                    baseNumerica bI16 = new baseNumerica(operandoTMP);//666666666666666Imprimo codigo maquina de codop
                    txtMensajes.Text += codop.getCodigoMaquina() + xb + System.Convert.ToString(bI16.getNumberHexadecimal()).PadLeft(2 * (codop.getBytesPorCalcular()-1), '0');
                    codigoMaquina = codop.getCodigoMaquina() + xb + System.Convert.ToString(bI16.getNumberHexadecimal()).PadLeft(2 * (codop.getBytesPorCalcular() - 1), '0');
                    break;
                case "[D,IDX]":
                    xb = "";
                    switch(arrayLine[3][3])
                    {
                        case 'X':
                            xb = "E7";
                            break;
                        case 'Y':
                            xb = "EF";
                            break;
                        case 'S':
                            xb = "F7";
                            break;
                        case 'P':
                            xb = "FF";
                            break;
                    }
                    txtMensajes.Text += codop.getCodigoMaquina() + xb;//77777777777777777777Imprimo codigo maquina de codop
                    codigoMaquina = codop.getCodigoMaquina() + xb;
                    break;
                case "IDX":
                    operandoFile.generaXB(codop);
                    txtMensajes.Text += codop.getCodigoMaquina() + operandoFile.getXb().PadLeft(2,'0');//88888888888Imprimo Codigo maquina de codop
                    codigoMaquina = codop.getCodigoMaquina() + operandoFile.getXb().PadLeft(2, '0');
                    break;
                case "IDX1":
                    operandoFile.generaXB(codop);
                    txtMensajes.Text += codop.getCodigoMaquina() + operandoFile.getXb();//999999999999999999999Imprimo codigo maquina de codop
                    codigoMaquina = codop.getCodigoMaquina() + operandoFile.getXb();
                    break;
                case "IDX2":
                    operandoFile.generaXB(codop);
                    txtMensajes.Text += codop.getCodigoMaquina() + operandoFile.getXb();//AAAAAAAAAAAAAAAImprimo codigo maquina de codop
                    codigoMaquina = codop.getCodigoMaquina() + operandoFile.getXb();
                    break;
                case "REL":
                    int indice = 0,tmp = 0;
                    Boolean flagFound = false;
                    foreach (String labelTMP in listaEtiquetas)
                    {
                        if (operandoFile.getOperando() == labelTMP)
                        {
                            indice = tmp;
                            flagFound = true;
                        }
                        tmp++;
                    }

                    if(flagFound)
                    {
                        tmp = 0;
                        String contLocLabel = "$";
                        foreach(String contlocTMP in dirEtiquetas)
                        {
                            if(tmp == indice)
                            {
                                contLocLabel += contlocTMP;
                            }
                            tmp++;
                        }
                        operandoFile.generaCodigoMaquina(contLocFile,codop,contLocLabel);
                        if (operandoFile.getFueraRango())
                        {
                            txtMensajes.Text += "FUERA DE RANGO ";
                            if(codop.getBytesPorCalcular() == 1)
                            {
                                txtMensajes.Text += "los rangos permitidos son de -128 hasta 127";
                            }
                            else
                            {
                                txtMensajes.Text += "los rangos permitidos son de -32768 hasta 32767";
                            }
                        }
                        else
                        {
                            txtMensajes.Text += codop.getCodigoMaquina().PadLeft(2, '0') + operandoFile.getXb();//BBBBBBBBBBBBBImprimo codigo maquina de codop
                            codigoMaquina = codop.getCodigoMaquina().PadLeft(2, '0') + operandoFile.getXb();
                        }
                    }
                    else
                    {
                        txtMensajes.Text += mensajesError[8];//Etiqueta no encontrada
                    }
                    break;
            }

            //Agregando informacion para posteriormente construir el S1
            arrayDirS1.Add(contLocFile);
            arrayCodMaqinaS1.Add(codigoMaquina);
            printEnter();
            GC.Collect();
        }
Example #8
0
        private void cargaCodop()
        {
            StreamReader objReader = new StreamReader("TABOP.data");
            String sLine = "";
            ArrayList arrText = new ArrayList();
            while (sLine != null)
            {
                sLine = objReader.ReadLine();
                if (sLine != null)
                    arrText.Add(sLine);
            }
            objReader.Close();
            char[] delimitadores = {'|'};
            int tam = arrText.Count;
            for(int i=0,j=0;i<tam;j++)
            {
                string tmp = Convert.ToString(arrText[i]);
                string[] partes = tmp.Split(delimitadores);
                string actual = Convert.ToString(partes[0]),analizando;
                analizando = actual;
                arrayTMPCODOP[j] = new TMPCODOP();
                arrayTMPCODOP[j].setName(actual);
                arrayTMPCODOP[j].setStart(i);
                while (actual == analizando)
                {
                    arrayCODOP[i] = new CODOP();
                    bool necesita;
                    if (Convert.ToChar(partes[1]) == 'f')
                    {
                        necesita = false;
                    }
                    else
                    {
                        necesita = true;
                    }
                    arrayCODOP[i].setCODOP(Convert.ToString(partes[0]), necesita, Convert.ToString(partes[2]),
                    Convert.ToString(partes[3]), Convert.ToInt16(partes[4]), Convert.ToInt16(partes[5]), Convert.ToInt16(partes[6]));

                    tmp = Convert.ToString(arrText[++i]);
                    partes = tmp.Split(delimitadores);
                    analizando = Convert.ToString(partes[0]);

                }
                arrayTMPCODOP[j].setEnd(i);
                if (i == 576) { i++; }
            }
        }