Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using System.IO;
- using System.Collections;
- using System.Drawing.Drawing2D;
- namespace Virtual_SicXe
- {
- public partial class Form1 : Form
- {
- public string[] Directives = {"START","END","BYTE","WORD","RESB","RESW" };
- public Hashtable SYMTAB = new Hashtable();
- public Hashtable optable = new Hashtable();
- public string LhexValue2;
- public string FileObj = "";
- public string objectprogram = "";
- public string[] opcodes = {"ADD"
- ,"ADDF"
- ,"ADDR"
- , "AND"
- , "CLEAR"
- ,"COMP"
- , "COMPF"
- , "COMPR"
- , "DIV"
- , "DIVF"
- , "DIVR"
- , "FIX"
- , "FLOAT"
- , "HIO"
- , "J"
- , "JEQ"
- , "JGT"
- , "JLT"
- , "JSUB"
- , "LDA"
- , "LDB"
- , "LDCH"
- , "LDF"
- , "LDL"
- , "LDS"
- , "LDT"
- , "LDX"
- , "LPS"
- , "MUL"
- , "MULF"
- , "MULR"
- , "NORM"
- , "OR"
- , "RD"
- , "RMO"
- , "RSUB"
- , "SHIFTL"
- , "SHIFTR"
- , "SIO"
- , "SSK"
- , "STA"
- , "STB"
- , "STCH"
- , "STF"
- , "STI"
- , "STL"
- , "STS"
- , "STSW"
- , "STT"
- , "STX"
- , "SUB"
- , "SUBF"
- , "SUBR"
- , "SVC"
- , "TD"
- , "TIO"
- , "TIX"
- , "TIXR"
- , "WD"
- };
- public string[] opcodetype ={"3",
- "3",
- "2",
- "3",
- "2",
- "3",
- "3",
- "2",
- "3",
- "3",
- "2",
- "1",
- "1",
- "1",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "2",
- "1",
- "3",
- "3",
- "2",
- "3",
- "2",
- "2",
- "1",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "3",
- "2",
- "2",
- "3",
- "1",
- "3",
- "2",
- "3", };
- public string intermediate = "";
- public string FinalObjectCode = "";
- public Form1()
- {
- InitializeComponent();
- this.StartPosition = System.Windows.Forms.FormStartPosition.Manual;
- optable.Add("ADD", "18");
- optable.Add("ADDF", "58");
- optable.Add("ADDR", "90");
- optable.Add("AND", "40");
- optable.Add("CLEAR", "B4");
- optable.Add("COMP", "28");
- optable.Add("COMPF", "88");
- optable.Add("COMPR", "A0");
- optable.Add("DIV", "24");
- optable.Add("DIVF", "64");
- optable.Add("DIVR", "9C");
- optable.Add("FIX", "C4");
- optable.Add("FLOAT", "C0");
- optable.Add("HIO", "F4");
- optable.Add("J", "3C");
- optable.Add("JEQ", "30");
- optable.Add("JGT", "34");
- optable.Add("JLT", "38");
- optable.Add("JSUB", "48");
- optable.Add("LDA", "00");
- optable.Add("LDB", "68");
- optable.Add("LDCH", "50");
- optable.Add("LDF", "70");
- optable.Add("LDL", "08");
- optable.Add("LDS", "6C");
- optable.Add("LDT", "74");
- optable.Add("LDX", "04");
- optable.Add("LPS", "D0");
- optable.Add("MUL", "20");
- optable.Add("MULF", "60");
- optable.Add("MULR", "98");
- optable.Add("NORM", "C8");
- optable.Add("OR", "44");
- optable.Add("RD", "D8");
- optable.Add("RMO", "AC");
- optable.Add("RSUB", "4C");
- optable.Add("SHIFTL", "A4");
- optable.Add("SHIFTR", "A8");
- optable.Add("SIO", "F0");
- optable.Add("SSK", "EC");
- optable.Add("STA", "0C");
- optable.Add("STB", "78");
- optable.Add("STCH", "54");
- optable.Add("STF", "80");
- optable.Add("STI", "D4");
- optable.Add("STL", "14");
- optable.Add("STS", "7C");
- optable.Add("STSW", "E8");
- optable.Add("STT", "84");
- optable.Add("STX", "10");
- optable.Add("SUB", "1C");
- optable.Add("SUBF", "5C");
- optable.Add("SUBR", "94");
- optable.Add("SVC", "B0");
- optable.Add("TD", "E0");
- optable.Add("TIO", "F8");
- optable.Add("TIX", "2C");
- optable.Add("TIXR", "B8");
- optable.Add("WD", "DC");
- }
- private void Form1_Load(object sender, EventArgs e){}
- private void loadFileToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- StreamReader sr;
- int StartAddress = 0;
- openFileDialog1.InitialDirectory = @"e:\";
- int line = 0;
- openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- label1.Show();
- label2.Show();
- tableLayoutPanel1.Controls.Add(new Label() { Text = "Line" }, 0, 0);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "Address" }, 1, 0);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "Symbol" }, 2, 0);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "Opcode" }, 3, 0);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "Operand" }, 4, 0);
- tableLayoutPanel2.Controls.Add(new Label() { Text = "Symbol" }, 0, 0);
- tableLayoutPanel2.Controls.Add(new Label() { Text = "Address" }, 1, 0);
- int i = 1;
- sr = new StreamReader(openFileDialog1.FileName);
- String x = sr.ReadLine();
- string aa = x.Substring(0, 8);
- string space1 = x.Substring(8, 1);
- string opcode = x.Substring(9, 6);
- string space2 = x.Substring(15, 2);
- string operand = x.Substring(17, 18);
- StartAddress = Convert.ToInt32(operand);
- if (!aa.Contains(" "))
- {
- SYMTAB.Add(aa, StartAddress);
- }
- tableLayoutPanel1.Controls.Add(new Label() { Text = line.ToString() }, 0, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = operand }, 1, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = aa }, 2, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = opcode }, 3, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = operand }, 4, i);
- string LOCCTR = StartAddress.ToString();
- string CurrentLoc;
- string Error = "";
- intermediate += LOCCTR + " " + x + Environment.NewLine;
- while ((x = sr.ReadLine()) != null)
- {
- string LhexValue = "";
- CurrentLoc = LOCCTR;
- i++;
- if (x.Substring(0, 1) == ".")
- {
- i--;
- continue;
- }
- aa = x.Substring(0, 8);
- space1 = x.Substring(8, 1);
- opcode = x.Substring(9, 6);
- if (opcode.Trim() == "END")
- {
- intermediate += " " + aa + space1 + opcode;
- }
- else
- {
- intermediate += LOCCTR + " " + x + Environment.NewLine;
- }
- if (opcode.Trim() == "END")
- {
- tableLayoutPanel1.Controls.Add(new Label() { Text = (++line).ToString() }, 0, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "" }, 1, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = aa }, 2, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = opcode }, 3, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = "" }, 4, i);
- break;
- }
- space2 = x.Substring(15, 2);
- operand = x.Substring(17, 18);
- string opcodeValue = opcode;
- if (opcodeValue.Substring(0, 1) == "+")
- {
- opcodeValue = opcodeValue.Substring(1, 5);
- }
- if (!optable.ContainsKey(opcodeValue.Trim()) && !Directives.Contains(opcodeValue.Trim()))
- {
- Error += "unidentified opcode at line : " + line;
- MessageBox.Show(Error);
- break;
- }
- int index_of_opcode = Array.IndexOf(opcodes, opcode.Trim());
- string type0="";
- if (index_of_opcode>0)
- type0 = opcodetype[index_of_opcode];
- if (!aa.Contains(" "))
- {
- if (SYMTAB.ContainsKey(aa))
- {
- Error += "Dublicate Symbol Table at line " + (line + 1);
- MessageBox.Show(Error);
- break;
- }
- else
- SYMTAB.Add(aa, CurrentLoc);
- }
- if (opcode.Substring(0, 1) == "+")
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += 4;
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else if (opcode == "RESB ")
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += int.Parse(operand);
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else if (opcode == "RESW ")
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += (int.Parse(operand) * 3);
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else if (opcode == "BYTE ")
- {
- string AsciiType = operand.Substring(0, 1);
- string op2 = operand.Substring(2);
- int j = 0;
- int cnt = 0;
- while (op2[j] != ' ')
- {
- cnt++;
- j++;
- }
- cnt -= 1;
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- if (AsciiType == "C")
- decAgain += cnt;
- else
- decAgain += cnt / 2;
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else if (type0=="2")
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += 2;
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else if (operand.Contains(" ") && opcode.Trim() !="RSUB")
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += 1;
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- else
- {
- int decAgain = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- decAgain += 3;
- LhexValue = decAgain.ToString("X");
- LOCCTR = LhexValue;
- }
- line++;
- tableLayoutPanel1.Controls.Add(new Label() { Text = line.ToString() }, 0, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = CurrentLoc }, 1, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = aa }, 2, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = opcode }, 3, i);
- tableLayoutPanel1.Controls.Add(new Label() { Text = operand }, 4, i);
- }
- label4.Text = LOCCTR;
- string srtAddress = StartAddress.ToString();
- int Fv = int.Parse(LOCCTR, System.Globalization.NumberStyles.HexNumber);
- Fv -= int.Parse(srtAddress, System.Globalization.NumberStyles.HexNumber);
- LhexValue2 = Fv.ToString("X");
- label6.Text = LhexValue2;
- ICollection key = SYMTAB.Keys;
- int cntr = 1;
- foreach (string k in key)
- {
- tableLayoutPanel2.Controls.Add(new Label() { Text = SYMTAB[k].ToString() }, 0, cntr);
- tableLayoutPanel2.Controls.Add(new Label() { Text = k }, 1, cntr);
- cntr++;
- }
- }
- }
- private void saveSymtabToolStripMenuItem1_Click(object sender, EventArgs e)
- {
- SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- saveFileDialog1.InitialDirectory = @"e:\";
- saveFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- ICollection key = SYMTAB.Keys;
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- string symboltable="";
- foreach(string k in key)
- {
- symboltable += k + ": " + SYMTAB[k] + Environment.NewLine;
- }
- File.WriteAllText(saveFileDialog1.FileName, symboltable);
- }
- }
- private void saveIntermediateFileToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- saveFileDialog1.InitialDirectory = @"e:\";
- saveFileDialog1.Filter = "Intermediate files (*.txt)|*.txt|All files (*.*)|*.*";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllText(saveFileDialog1.FileName, intermediate);
- }
- }
- private void tableLayoutPanel1_CellPaint(object sender, TableLayoutCellPaintEventArgs e){}
- private void button1_Click(object sender, EventArgs e){}
- private void button2_Click(object sender, EventArgs e){}
- private void button3_Click(object sender, EventArgs e){}
- private void label7_Click(object sender, EventArgs e){}
- private void openIntermediateToolStripMenuItem_Click(object sender, EventArgs e)
- {
- OpenFileDialog openFileDialog1 = new OpenFileDialog();
- openFileDialog1.InitialDirectory = @"e:\";
- openFileDialog1.Filter = "txt files (*.txt)|*.txt|All files (*.*)|*.*";
- if (openFileDialog1.ShowDialog() == DialogResult.OK)
- {
- //**************************************************
- //*********************biginPass2*******************
- //**************************************************
- string aaaadddddd = File.ReadAllText(openFileDialog1.FileName);
- Hashtable registers = new Hashtable();
- registers.Add("A", "0");
- registers.Add("X", "1");
- registers.Add("L", "2");
- registers.Add("B", "3");
- registers.Add("S", "4");
- registers.Add("T", "5");
- registers.Add("F", "6");
- registers.Add("PC", "8");
- registers.Add("SW", "9");
- string[] words = aaaadddddd.Split('\n');
- string objectcode = "";
- string type;
- string ProgramName = "";
- string Pass2Err = "";
- int cntINTER = 1;
- string StartingAddr = "";
- string StartingAddrForI = "";
- foreach (string strrr in words)
- {
- if (strrr == "")
- {
- continue;
- }
- string aa2 = strrr.Substring(7, 8);
- string space12 = strrr.Substring(15, 1);
- string opcode2 = strrr.Substring(16, 6);
- string space22 = strrr.Substring(22, 2);
- StartingAddrForI = strrr.Substring(0, 4);
- string operand2 = strrr.Substring(24, 18);
- string OperandTemp = operand2;
- if (operand2.Substring(0, 1) == "@")
- operand2 = operand2.Substring(1);
- string nextInst = words[cntINTER + 1].Substring(0, 4);//strrr.Substring(0, 4);
- string currentLocFORBYTE = strrr.Substring(1, 4);
- if (opcode2.Trim() == "START")
- {
- ProgramName = aa2;
- StartingAddr = "00" + strrr.Substring(0, 4);
- continue;
- }
- string opcodeValue = opcode2;
- if (opcodeValue.Substring(0, 1) == "+")
- {
- opcodeValue = opcodeValue.Substring(1, 5);
- }
- if (opcodeValue.Trim() == "RESW" || opcodeValue.Trim() == "RESB")
- {
- continue;
- }
- if (opcodeValue.Trim() == "BYTE")
- {
- string AsciiType = operand2.Substring(0, 1);
- string op2 = operand2.Substring(2);
- int j = 0;
- int cnt = 0;
- while (op2[j] != ' ')
- {
- cnt++;
- j++;
- }
- cnt -= 1;
- char ch;
- // the following lines for pass 2
- if (AsciiType == "C")
- {
- string hexV = "";
- for (j = 0; j < cnt; j++)
- {
- ch = op2[j];
- byte ByteOp = Convert.ToByte(ch);
- hexV += ByteOp.ToString("x");
- }
- objectcode = hexV;
- }
- else
- {
- string hexV = "";
- for (j = 0; j < cnt; j++)
- {
- hexV += op2[j];
- }
- objectcode = hexV;
- }
- }
- else if (opcodeValue.Trim() == "WORD")
- {
- int decAgain = int.Parse(operand2.Trim());
- string LhexValue = decAgain.ToString("X");
- if (LhexValue.Length == 1)
- LhexValue = "00000" + LhexValue;
- else if (LhexValue.Length == 2)
- LhexValue = "0000" + LhexValue;
- else if (LhexValue.Length == 3)
- LhexValue = "000" + LhexValue;
- else if (LhexValue.Length == 4)
- LhexValue = "00" + LhexValue;
- else if (LhexValue.Length == 5)
- LhexValue = "0" + LhexValue;
- objectcode = LhexValue;
- }
- else if (opcodeValue.Trim() == "RSUB")
- {
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "11";
- string hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- objectcode = hexopcode.Substring(0, 1) + hexout + "0000";
- }
- else
- {
- int index_of_opcode1 = Array.IndexOf(opcodes, opcodeValue.Trim());
- type = opcodetype[index_of_opcode1];
- if (OperandTemp.Contains(",X") && type != "2")
- {
- operand2 = operand2.Substring(0, operand2.IndexOf(","));
- operand2 += " ";
- }
- if (type == "1")
- {
- objectcode = optable[opcodeValue.Trim()].ToString();
- }
- else if (type == "2")
- {
- objectcode = optable[opcodeValue.Trim()].ToString();
- string reg1 = operand2.Substring(0, 1);
- string reg2 = operand2.Substring(2, 1);
- objectcode += registers[reg1];
- if (reg2 != " ")
- {
- objectcode += registers[reg2];
- }
- else
- {
- objectcode += 0;
- }
- }
- else if (type == "3")
- {
- if (operand2.Substring(0, 1) == "#")
- {
- if (int.Parse((operand2.Substring(1, 17)).Trim()) >= 0 && int.Parse((operand2.Substring(1, 17)).Trim()) <= 4095)
- {
- string immediatevalue = (operand2.Substring(1, 17)).Trim();
- string immediatehex = int.Parse(immediatevalue).ToString("X");
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "01";
- string hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- if (immediatehex.Length == 1)
- {
- immediatehex = "00" + immediatehex;
- }
- if (immediatehex.Length == 2)
- {
- immediatehex = "0" + immediatehex;
- }
- objectcode = hexopcode.Substring(0, 1) + hexout + "0" + immediatehex;
- }
- else if (int.Parse((operand2.Substring(1, 17)).Trim()) >= 4096 && opcode2.Substring(0, 1) == "+")
- {
- string immediatevalue = (operand2.Substring(1, 17)).Trim();
- string immediatehex = int.Parse(immediatevalue).ToString("X");
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "01";
- string hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- if (immediatehex.Length == 4)
- {
- immediatehex = "0" + immediatehex;
- }
- objectcode = hexopcode.Substring(0, 1) + hexout + "1" + immediatehex;
- }
- }
- else if (!operand2.Equals(""))
- {
- //compute TA-PC
- int diff = 0;
- int progCTR = int.Parse(nextInst, System.Globalization.NumberStyles.HexNumber);
- string locTarADD;
- bool SymLoc2 = (SYMTAB.ContainsKey(operand2.Substring(0, 8)));
- int loctaradd = 0;
- if (SymLoc2)
- {
- string targetADD = operand2.Substring(0, 8).ToString();
- locTarADD = SYMTAB[targetADD].ToString();
- loctaradd = int.Parse(locTarADD, System.Globalization.NumberStyles.HexNumber);
- }
- if (loctaradd < progCTR)
- {
- diff = (progCTR - loctaradd);
- }
- else
- diff = loctaradd - progCTR;
- if (opcode2.Substring(0, 1) == "+")
- {
- bool SymLoc = (SYMTAB.ContainsKey(operand2.Substring(0, 8)));
- if (SymLoc)
- {
- string operandSYMTBL = operand2.Substring(0, 8).ToString();
- string LocationSYMBOL = SYMTAB[operandSYMTBL].ToString();
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "11";
- string hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- if (LocationSYMBOL.Length == 4)
- {
- LocationSYMBOL = "0" + LocationSYMBOL;
- }
- objectcode = hexopcode.Substring(0, 1) + hexout + "1" + LocationSYMBOL;
- }//else generate error
- else
- {
- Pass2Err += "unidentified Symbol Location for " + opcode2 + " instruction.";
- MessageBox.Show(Pass2Err);
- }
- }
- else if (diff >= -2048 && diff <= 2047)
- {
- string disp;
- if (loctaradd < progCTR)
- {
- //Convert To 2
- string hx = diff.ToString();
- ushort intVal = Convert.ToUInt16(hx, 16);
- ushort twosComp = (ushort)(~intVal + 1); // twosComp == 4294902016
- string h = string.Format("{0:X}", twosComp); // h == "FFFF0100"
- disp = h.Substring(1, 3).ToString();
- }
- else
- disp = diff.ToString("X");
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "11";
- string hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- if (disp.Length == 1)
- {
- disp = "00" + disp;
- }
- if (disp.Length == 2)
- {
- disp = "0" + disp;
- }
- objectcode = hexopcode.Substring(0, 1) + hexout + "2" + disp;
- }
- }
- if (OperandTemp.Substring(0, 1) == "@")
- {
- string hexopcode = optable[opcodeValue.Trim()].ToString();
- string binaryopcode = Convert.ToString(Convert.ToInt32(hexopcode.Substring(1, 1), 16), 2).PadLeft(4, '0');
- string binaryout = binaryopcode.Substring(0, 2) + "10";
- string hexout;
- if (binaryout.Length == 4)
- {
- hexout = "0" + Convert.ToInt32(binaryout, 2).ToString("X");
- }
- else
- hexout = Convert.ToInt32(binaryout, 2).ToString("X");
- objectcode = hexout + objectcode.Substring(2);
- }
- if (OperandTemp.Contains(",X") && type != "2")
- {
- string hexopcode = objectcode.Substring(2, 1);
- int binaryopcode = Convert.ToInt32(hexopcode.Substring(0, 1), 16);
- int binaryopcode2 = Convert.ToInt32("8", 16);
- int res = binaryopcode + binaryopcode2;
- string binaryout = res.ToString("X");
- objectcode = objectcode.Substring(0, 2) + binaryout + objectcode.Substring(3);
- }
- }
- }
- objectcode += Environment.NewLine;
- FinalObjectCode += objectcode;
- cntINTER++;
- OperandTemp = "";
- }
- string[] Fobj = FinalObjectCode.Split('\n');
- FileObj = "H^" + ProgramName.Trim() + " " + "^" + StartingAddr + "^" + "00" + LhexValue2;
- objectprogram += FileObj;
- int NumOfchars = 0;
- FileObj = Environment.NewLine + "T";
- for (int k = 0; k < Fobj.Length; k++)
- {
- FileObj += "^" + Fobj[k];
- NumOfchars += Fobj[k].Length;
- if (NumOfchars > 60)
- {
- NumOfchars -= Fobj[k].Length;
- NumOfchars /= 2;
- NumOfchars -= 1;
- FileObj = FileObj.Substring(0, 10) + "^" + NumOfchars.ToString("X") + "^" + FileObj.Substring(4);
- objectprogram += FileObj;
- FileObj = "";
- NumOfchars = 0;
- FileObj = Environment.NewLine + "T";
- }
- }
- NumOfchars -= Fobj[Fobj.Length - 1].Length;
- NumOfchars /= 2;
- NumOfchars -= 2;
- FileObj = FileObj.Substring(0, 10) + "^0" + NumOfchars.ToString("X") + "^" + FileObj.Substring(4);
- objectprogram += FileObj;
- FileObj = Environment.NewLine + "E^" + StartingAddr;
- objectprogram += FileObj;
- MessageBox.Show("succefull");
- }
- }
- private void saveObjectProgramToolStripMenuItem_Click(object sender, EventArgs e)
- {
- SaveFileDialog saveFileDialog1 = new SaveFileDialog();
- saveFileDialog1.InitialDirectory = @"e:\";
- saveFileDialog1.Filter = "Intermediate files (*.txt)|*.txt|All files (*.*)|*.*";
- if (saveFileDialog1.ShowDialog() == DialogResult.OK)
- {
- File.WriteAllText(saveFileDialog1.FileName, objectprogram);
- MessageBox.Show("succefull");
- }
- }
- private void tableLayoutPanel2_Paint(object sender, PaintEventArgs e)
- {
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement