private void toolStripMapa_ItemClicked(object sender, ToolStripItemClickedEventArgs e) { switch (e.ClickedItem.AccessibleName) { case "Abrir": if (openFileObj.ShowDialog().Equals(DialogResult.OK)) { sicEstandar = new SICEstandar(openFileObj.FileName); CP = MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.CP)); A = MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.A); X = MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.X); L = MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.L); this.richTextBox1.Text = ""; this.llenaDataGrid(); } break; } }
protected override void creaArchivoObj() { string linea; string[] instruccion; this.archivoObj = new List<string>(); instruccion = this.intermedio.First().Split('\t'); this.nombreProg = MetodosAuxiliares.ajustaCadena(instruccion[1], 6); linea = instruccion[3].Replace("H", ""); linea = linea.Replace("h", ""); linea = "H" + nombreProg + MetodosAuxiliares.ajustaDireccion(linea) + MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.tamaño)); this.archivoObj.Add(linea); this.relocalizables = new List<string>(); this.generaRegistrosT(); this.generaRegistrosM(); instruccion = this.intermedio.Last().Split('\t'); linea = "E" + this.calculaDireccionEnd(instruccion[3]); this.archivoObj.Add(linea); }
private bool relativoBase(ref string operando) { bool band; long desp; long dir; band = false; if (tabSim.TryGetValue(operando, out dir)) { desp = dir - b; if (desp >= 0 & desp <= 4095) { operando = MetodosAuxiliares.decimalAHexadecimal(desp); operando = MetodosAuxiliares.ajustaOperando(operando, 3, "0"); band = true; } } return band; }
private string STL(string m) { // m..m+2 ← (L) string mensaje; string[] operando; string aux; char[] aux2; operando = this.obtenOperando(m); mensaje = "(m, m+1, m+2) ← (L)\n"; mensaje = "\t\t (m, m+1, m+2) ← " + MetodosAuxiliares.decimalAHexadecimal(this.l); aux = MetodosAuxiliares.decimalAHexadecimal(this.l); aux2 = aux.ToCharArray(); operando[0] = Convert.ToString(aux2[0]) + Convert.ToString(aux2[1]); operando[1] = Convert.ToString(aux2[2]) + Convert.ToString(aux2[3]); operando[2] = Convert.ToString(aux2[4]) + Convert.ToString(aux2[5]); this.memoria.almacenaDatos(operando, 3, m); mensaje = "\t\t (m, m+1, m+2) ← " + operando[0] + operando[1] + operando[2]; return(mensaje); }
protected override void ensamblaIntermedio(DataGridView dataGridViewIntermedio, string[] codigo, int i, string error) { if (!error.Equals("Vacia")) { if (codigo.Length == 3) { dataGridViewIntermedio.Rows.Add(i + 1, MetodosAuxiliares.decimalAHexadecimal(this.cp), codigo[0], codigo[1], codigo[2], error); this.intermedio.Add(MetodosAuxiliares.decimalAHexadecimal(this.cp) + "\t" + this.archivo[i] + "\t" + error); } else if (codigo.Length == 2) { dataGridViewIntermedio.Rows.Add(i + 1, MetodosAuxiliares.decimalAHexadecimal(this.cp), codigo[0], codigo[1], "", error); this.intermedio.Add(MetodosAuxiliares.decimalAHexadecimal(this.cp) + "\t" + this.archivo[i] + "\t\t" + error); } } else { dataGridViewIntermedio.Rows.Add(i + 1, MetodosAuxiliares.decimalAHexadecimal(this.cp), codigo[0], codigo[1], codigo[2], error); this.intermedio.Add(MetodosAuxiliares.decimalAHexadecimal(this.cp) + "\t\t\t\t" + error); } }
public string ObtenM(ref long cp) { int i; int j; string m; string cpHex; cpHex = MetodosAuxiliares.decimalAHexadecimal(cp); i = (int)this.ObtenFila(cpHex); j = (int)MetodosAuxiliares.hexadecimalADecimal(cpHex.Last().ToString()); m = this.mapa[i, j]; j++; if (j > 16) { i++; j = 0; } m += this.mapa[i, j]; cp += 2; return(m); }
private void llenaDataGrid() { this.limpiaDatagrid(); string[] fila; fila = new string[17]; for (int i = 0; i < sicEstandar.Memoria.Filas; i++) { fila[0] = MetodosAuxiliares.decimalAHexadecimal(MetodosAuxiliares.hexadecimalADecimal(sicEstandar.Memoria.Inicio) + (i * 16)); for (int j = 0; j < sicEstandar.Memoria.Columnas; j++) { fila[j + 1] = sicEstandar.Memoria.Mapa[i, j]; } this.dataGridViewMapaDeMemoria.Rows.Add(fila); } this.dataGridViewRegistros.Rows.Add("CP", CP, MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.CP))); this.dataGridViewRegistros.Rows.Add("A", A, MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.A))); this.dataGridViewRegistros.Rows.Add("X", X, MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.X))); this.dataGridViewRegistros.Rows.Add("L", L, MetodosAuxiliares.ajustaDireccion(MetodosAuxiliares.decimalAHexadecimal(this.sicEstandar.L))); this.dataGridViewRegistros.Rows.Add("CC", this.sicEstandar.CC, ""); this.label1.Text = "Tamaño del programa:" + this.sicEstandar.Memoria.Tamaño; }
private string STX(string m)//// { // m..m+2 ← (X) string mensaje; string[] operando; string aux; char[] aux2; operando = this.obtenOperando(m); mensaje = "(m, m+1, m+2) ← (X)\n"; mensaje = "\t\t (m, m+1, m+2) ← " + MetodosAuxiliares.decimalAHexadecimal(this.x); aux = MetodosAuxiliares.decimalAHexadecimal(this.x); aux2 = aux.ToCharArray(); operando[0] = Convert.ToString(aux2[0]) + Convert.ToString(aux2[1]); operando[1] = Convert.ToString(aux2[2]) + Convert.ToString(aux2[3]); operando[2] = Convert.ToString(aux2[4]) + Convert.ToString(aux2[5]); this.Memoria.almacenaDatos(operando, 3, m); //mensaje = "\t\t (m, m+1, m+2) ← " + Paso1.convierteHEX(Convert.ToInt32(operando[0])) + Paso1.convierteHEX(Convert.ToInt32(operando[1])) + Paso1.convierteHEX(Convert.ToInt32(operando[2])); mensaje = "\t\t (m, m+1, m+2) ← " + operando[0] + operando[1] + operando[2]; return(mensaje); }
private string TIX(string m) { string mensaje; string[] operando; long decM; mensaje = "Efecto: X ← (X) + 1; (X) : (m..m+2) \n" + "Incrementa el valor de X en 1 y lo compara con una \n" + "palabra en memoria y establece el código de \n" + "condición para indicar el resultado(<, = o >) \n"; operando = this.obtenOperando(m); mensaje = "\t X ← " + MetodosAuxiliares.decimalAHexadecimal(this.x) + " + 1; " + MetodosAuxiliares.decimalAHexadecimal(this.x) + " : " + operando[0] + operando[1] + operando[2] + "\n"; decM = MetodosAuxiliares.hexadecimalADecimal(operando[0] + operando[1] + operando[2]); this.x++; if (this.x == decM) { this.cc = "="; } else if (this.x > decM) { this.cc = ">"; } else if (this.x < decM) { this.cc = "<"; } mensaje += "\t\t Resultado: X ← " + MetodosAuxiliares.decimalAHexadecimal(this.x) + "; CC ← " + this.cc; return(mensaje); }
public override void paso2(DataGridView dataGridViewIntermedio) { bool x; int resto; string aux; char[] cadena; string[] linea; this.codigoObj = new string[this.intermedio.Count]; for (int i = 0; i < this.intermedio.Count; i++) { linea = this.intermedio[i].Split('\t'); if (!string.IsNullOrEmpty(linea[2])) { if (!this.lineasError[i]) { if (this.instrucciones.Keys.Contains(linea[2]) | linea[2].Equals("WORD") | linea[2].Equals("BYTE")) { switch (linea[2]) { case "BYTE": #region Byte if (linea[3].Contains("X") | linea[3].Contains("x")) { //FE codigoObj[i] = linea[3].Replace("X'", ""); codigoObj[i] = codigoObj[i].Replace("x'", ""); codigoObj[i] = codigoObj[i].Replace("'", ""); } else { codigoObj[i] = linea[3].Replace("C'", ""); codigoObj[i] = codigoObj[i].Replace("c'", ""); codigoObj[i] = codigoObj[i].Replace("'", ""); codigoObj[i] = MetodosAuxiliares.ASCIIToHexadecimal(codigoObj[i]); } #endregion break; case "WORD": #region WORD x = linea[3].Contains("H") | linea[3].Contains("h"); codigoObj[i] = linea[3].Replace("h", ""); codigoObj[i] = linea[3].Replace("H", ""); if (!x) { codigoObj[i] = MetodosAuxiliares.decimalAHexadecimal(int.Parse(codigoObj[i])); } if (codigoObj[i].Length < 6) { resto = 6 - codigoObj[i].Length; aux = ""; for (int j = 0; j < resto; j++) { aux += "0"; } codigoObj[i] = aux + codigoObj[i]; } else if (codigoObj[i].Length > 6) { codigoObj[i] = codigoObj[i].Substring(0, 6); } #endregion break; default: #region Instrucciones if (!linea[2].Equals("RSUB")) { linea[3] = linea[3].Replace(" ", ""); x = linea[3].Contains(",X") | linea[3].Contains(",x"); linea[3] = linea[3].Replace(",X", ""); linea[3] = linea[3].Replace(",x", ""); if (this.tabSim.Keys.Contains(linea[3])) { codigoObj[i] = this.instrucciones[linea[2]] + MetodosAuxiliares.decimalAHexadecimal(this.tabSim[linea[3]]); } else { codigoObj[i] = this.instrucciones[linea[2]] + "7FFF"; } if (x) { codigoObj[i] = MetodosAuxiliares.hexadecimalABinario(codigoObj[i]); cadena = codigoObj[i].ToCharArray(); cadena[8] = '1'; codigoObj[i] = new string(cadena); codigoObj[i] = MetodosAuxiliares.decimalAHexadecimal(MetodosAuxiliares.binarioADecimal(codigoObj[i])); } } else { codigoObj[i] = this.instrucciones[linea[2]] + "0000"; } #endregion break; } } else { codigoObj[i] = "---"; } } else { codigoObj[i] = "Error: de Sintaxis"; } } else { this.codigoObj[i] = "Error: Linea vacia"; } } this.ensamblaIntermedio(dataGridViewIntermedio); this.creaArchivoObj(); }
protected override void generaRegistrosT() { int i; int j; string registroT; string aux; string bytes; aux = ""; i = 1; while (!this.archivo[i].Contains("END")) { registroT = "T" + MetodosAuxiliares.ajustaDireccion(this.intermedio[i].Split('\t').First()); for (j = i; j < this.codigoObj.Length - 1; j++) { if (!this.codigoObj[j].Contains("Error")) { if (this.codigoObj[j].Contains("*")) { string cpHex; cpHex = MetodosAuxiliares.decimalAHexadecimal(MetodosAuxiliares.hexadecimalADecimal(this.intermedio[j].Split('\t').First()) +1); this.relocalizables.Add(MetodosAuxiliares.ajustaOperando(cpHex,6,"0")); this.codigoObj[j] = this.codigoObj[j].Replace("*", ""); } if (((aux.Length + this.codigoObj[j].Length) / 2) > 30) { break; } else if (this.codigoObj[j].Equals("---") & !this.archivo[j].Contains("BASE")) { break; } else if(!this.archivo[j].Contains("BASE")) { aux += this.codigoObj[j]; } } } bytes = MetodosAuxiliares.decimalAHexadecimal(aux.Length / 2); if (bytes.Length < 2) { bytes = "0" + bytes; } registroT += bytes; registroT += aux; aux = ""; if (registroT.Length > 9) { this.archivoObj.Add(registroT); } for (int k = j; k < this.codigoObj.Length; k++) { if (!codigoObj[k].Equals("---") | this.intermedio[k].Contains("END")) { i = k; break; } } } }
private string ensamblaInstruccion3(string codOp, string operando, string cpSig) { string codigoObj; char[] nixbpe; codigoObj = ""; nixbpe = new char[6]; codigoObj = MetodosAuxiliares.hexadecimalABinario(this.instruccionesFormato3[codOp]).Substring(4,2); nixbpe[5] = '0'; if (!codOp.Equals("RSUB")) { codOp = this.instruccionesFormato3[codOp][0].ToString(); switch (operando.First()) { case '@'://Direccionamiento Indirecto nixbpe[0] = '1'; nixbpe[1] = '0'; nixbpe[2] = '0'; operando = operando.Replace("@",""); break; case '#'://Direccionamiento Inmediato nixbpe[0] = '0'; nixbpe[1] = '1'; nixbpe[2] = '0'; operando = operando.Replace("#", ""); break; default://Direccionamiento Simple nixbpe[0] = '1'; nixbpe[1] = '1'; if (operando.Contains(",X") | operando.Contains(",x")) { operando = operando.Replace(",X", ""); operando = operando.Replace(",x", ""); nixbpe[2] = '1'; } else { nixbpe[2] = '0'; } break; } if (this.tabSim.Keys.Contains(operando)) { this.determinaBanderas(ref nixbpe, ref operando, cpSig); } else { bool h; h = operando.Last().Equals('H') | operando.Last().Equals('h'); if (h) { operando = operando.Replace("H", ""); operando = operando.Replace("h", ""); } if (Information.IsNumeric(operando)) { if (h) { operando = MetodosAuxiliares.hexadecimalADecimal(operando).ToString(); } int c; c = int.Parse(operando); operando = MetodosAuxiliares.decimalAHexadecimal(c); if (0 <= c & c <= 4095) { nixbpe[3] = '0'; nixbpe[4] = '0'; operando = MetodosAuxiliares.ajustaOperando(operando, 3, "0"); } else { this.determinaBanderas(ref nixbpe, ref operando, cpSig); } } else { nixbpe[3] = '1'; nixbpe[4] = '1'; operando = "FFF"; } } codigoObj += new string(nixbpe); codigoObj = codOp + MetodosAuxiliares.decimalAHexadecimal(MetodosAuxiliares.binarioADecimal(codigoObj)) + operando; } else { codigoObj = "4F0000"; } return codigoObj; }
private string ensamblaInstruccion4(string codOp, string operando) { string codigoObj; char[] nixbpe; codigoObj = ""; long dir; int resto; nixbpe = new char[6]; codigoObj = MetodosAuxiliares.hexadecimalABinario(this.instruccionesFormato4[codOp]).Substring(0, 6); nixbpe[3] = '0'; nixbpe[4] = '0'; nixbpe[5] = '1'; if (!codOp.Equals("RSUB")) { switch (operando.First()) { case '@'://Direccionamiento Indirecto nixbpe[0] = '1'; nixbpe[1] = '0'; nixbpe[2] = '0'; operando = operando.Replace("@", ""); break; case '#'://Direccionamiento Inmediato nixbpe[0] = '0'; nixbpe[1] = '1'; nixbpe[2] = '0'; operando = operando.Replace("#", ""); break; default://Direccionamiento Simple nixbpe[0] = '1'; nixbpe[1] = '1'; if (operando.Contains(",X") | operando.Contains(",x")) { operando = operando.Replace(",X", ""); operando = operando.Replace(",x", ""); nixbpe[2] = '1'; } else { nixbpe[2] = '0'; } break; } if (tabSim.TryGetValue(operando, out dir)) { operando = MetodosAuxiliares.decimalAHexadecimal(dir); } else { bool h; h = operando.Last().Equals('H') | operando.Last().Equals('h'); if (h) { operando = operando.Replace("H", ""); operando = operando.Replace("h", ""); } if (Information.IsNumeric(operando)) { if (h) { operando = MetodosAuxiliares.hexadecimalADecimal(operando).ToString(); } int c; c = int.Parse(operando); if (c > 4095) { operando = MetodosAuxiliares.decimalAHexadecimal(c); } else { operando = "FFFFF"; } } else { operando = "FFFFF"; } } if (MetodosAuxiliares.hexadecimalADecimal(operando) > 0) { operando = MetodosAuxiliares.ajustaOperando(operando, 5, "0"); } else { operando = MetodosAuxiliares.ajustaOperando(operando, 5, "F"); } codigoObj = MetodosAuxiliares.decimalAHexadecimal(MetodosAuxiliares.binarioADecimal(codigoObj + new string(nixbpe))) + operando; codigoObj += "*"; } else { codigoObj = "4F100000*"; } return codigoObj; }
public override void paso2(DataGridView dataGridViewIntermedio) { bool x; int resto; string aux; string[] linea; string[] lineaSig; this.asignaBase(); this.codigoObj = new string[this.intermedio.Count]; for (int i = 0; i < this.intermedio.Count; i++) { linea = this.intermedio[i].Split('\t'); if (!string.IsNullOrEmpty(linea[2])) { if (!this.lineasError[i]) { if (this.instruccionesFormato1.Keys.Contains(linea[2])) { this.codigoObj[i] = this.instruccionesFormato1[linea[2]]; } else if(this.instruccionesFormato2.Keys.Contains(linea[2])) { this.codigoObj[i] = this.ensamblaInstruccion2(linea[2], linea[3]); } else if (this.instruccionesFormato3.Keys.Contains(linea[2])) { lineaSig = this.intermedio[i+1].Split('\t'); this.codigoObj[i] = this.ensamblaInstruccion3(linea[2], linea[3], lineaSig[0]); } else if (this.instruccionesFormato4.Keys.Contains(linea[2])) { this.codigoObj[i] = this.ensamblaInstruccion4(linea[2], linea[3]); } else { switch (linea[2]) { case "BYTE": #region Byte if (linea[3].Contains("X") | linea[3].Contains("x")) { //FE codigoObj[i] = linea[3].Replace("X'", ""); codigoObj[i] = codigoObj[i].Replace("x'", ""); codigoObj[i] = codigoObj[i].Replace("'", ""); if (codigoObj[i].Length % 2 != 0) { codigoObj[i] = "0" + codigoObj[i]; } } else { codigoObj[i] = linea[3].Replace("C'", ""); codigoObj[i] = codigoObj[i].Replace("c'", ""); codigoObj[i] = codigoObj[i].Replace("'", ""); codigoObj[i] = MetodosAuxiliares.ASCIIToHexadecimal(codigoObj[i]); } #endregion break; case "WORD": #region WORD x = linea[3].Contains("H") | linea[3].Contains("h"); codigoObj[i] = linea[3].Replace("h", ""); codigoObj[i] = linea[3].Replace("H", ""); if (!x) { codigoObj[i] = MetodosAuxiliares.decimalAHexadecimal(int.Parse(codigoObj[i])); } if (codigoObj[i].Length < 6) { resto = 6 - codigoObj[i].Length; aux = ""; for (int j = 0; j < resto; j++) { aux += "0"; } codigoObj[i] = aux + codigoObj[i]; } else if (codigoObj[i].Length > 6) { codigoObj[i] = codigoObj[i].Substring(0, 6); } #endregion break; default: this.codigoObj[i] = "---"; break; } } } else { codigoObj[i] = "Error: de Sintaxis"; } } else { this.codigoObj[i] = "Error: Linea vacia"; } } this.ensamblaIntermedio(dataGridViewIntermedio); this.creaArchivoObj(); }