public Instruction(int Bin, int Address, ref RegisterFile regin, ref asmLabel label) { binary = Bin; rf = regin; BaseAddress = Address; Label = label; ASM = asmLookUp(Bin); }
public Instruction(int Bin, int Address, ref RegisterFile regin, String label) { binary = Bin; rf = regin; BaseAddress = Address; Label = new asmLabel(label, BaseAddress); ASM = asmLookUp(Bin); }
/// <summary> /// Constructor for an Instruction with a known memory location. Decompiles /// the binary data into its assembly mnemonic. /// </summary> /// <param name="Bin">14-bit Binary containing the instruction.</param> /// <param name="Address">Memory location of the instruction.</param> public Instruction(int Bin, int Address) { binary = Bin; rf = new RegisterFile(); BaseAddress = Address; Label = new asmLabel("", BaseAddress); ASM = asmLookUp(Bin); }
/// <summary> /// Empty Instruction constructor. Generates a NOP instruction at memory /// address 0x0000; /// </summary> public Instruction() { binary = 0; BaseAddress = 0; rf = new RegisterFile(); Label = new asmLabel("", BaseAddress); ASM = "NOP"; mnemonic = ASM; }
public Instruction(int Bin, int Address, ref RegisterFile regin, ref asmLabel label, ref Stack <int> ptrTOS) { // TODO: Complete member initialization binary = Bin; rf = regin; BaseAddress = Address; Label = label; ASM = asmLookUp(Bin); stck = ptrTOS; }
public void setLabel(ref asmLabel label) { Label = label; Label.placed = true; }
/// <summary> /// Function to decompile the lines read from a hex file. /// </summary> /// <returns>List with the flash memory abstraction.</returns> public List <picWord> decompile() { int Bytes, BaseAddress, CheckSum, i, bin; DataTypes DataType; List <int> DataBytes = new List <int>(); List <picWord> sourceISA = new List <picWord>(); foreach (String line in HexCode) { Bytes = Convert.ToInt32(line.Substring(1, BYTEBLOCK), 16); BaseAddress = Convert.ToInt32(line.Substring(BYTEBLOCK + 1, 2 * BYTEBLOCK), 16) >> 1; DataType = (DataTypes)Convert.ToInt32(line.Substring(3 * BYTEBLOCK + 1, BYTEBLOCK), 16); if (BaseAddress == 0x2007) { // This is a configuration word... and its extremely poorly documented... bin = Convert.ToInt32(line.Substring(5 * BYTEBLOCK + 1, BYTEBLOCK) + line.Substring(4 * BYTEBLOCK + 1, BYTEBLOCK), 16); sourceISA.Add(new picWord(bin, BaseAddress)); continue; } else if (DataType == DataTypes.ExtendedAddress) { // This is data which was placed in the the PIC's flash memory. To avoid using the limited RAM. for (i = 0; i < (Bytes * BYTEBLOCK) && (DataType == DataTypes.Program); i += 2 * BYTEBLOCK) { // Due to the little endian design of the instruction format, bytes need to be reverse in order to be usable. bin = Convert.ToInt32(line.Substring(i + 5 * BYTEBLOCK + 1, BYTEBLOCK) + line.Substring(i + 4 * BYTEBLOCK + 1, BYTEBLOCK), 16); sourceISA.Add(new picWord(bin, BaseAddress)); } } else { // This is an insrucion block. for (i = 0; i < (Bytes * BYTEBLOCK) && (DataType == DataTypes.Program); i += 2 * BYTEBLOCK) { Queue <asmLabel> Labels = new Queue <asmLabel>(); Instruction I; asmLabel L; String[] args; // Due to the little endian design of the instruction format, bytes need to be reverse in order to be usable. bin = Convert.ToInt32(line.Substring(i + 5 * BYTEBLOCK + 1, BYTEBLOCK) + line.Substring(i + 4 * BYTEBLOCK + 1, BYTEBLOCK), 16); DataBytes.Add(bin); try { // Start the BT by modifying the CPU Registers. L = new asmLabel("", BaseAddress); I = new Instruction(bin, BaseAddress + i / (2 * BYTEBLOCK), ref rf, ref ptrTOS); args = I.getargs(); int addr = I.getAddress(); switch (I.getmnemonic()) { // Managing labels while decompiling. case "CALL": args = I.getargs(); addr = bin & 0x07FF; L.label = args[0]; L.address = addr; if (addr < I.getAddress()) { sourceISA.Find(x => x.getAddress() == addr).setLabel(ref L); } else { Labels.Enqueue(new asmLabel(args[0], addr)); } break; case "GOTO": args = I.getargs(); addr = bin & 0x07FF; L.label = args[0]; L.address = addr; if (addr < I.getAddress()) { sourceISA.Find(x => x.getAddress() == addr).setLabel(ref L); } else { Labels.Enqueue(new asmLabel(args[0], addr)); } break; default: break; } if ((Labels.Count > 0) && (I.getAddress() == Labels.Peek().address)) { L = Labels.Dequeue(); I.setLabel(ref L); } sourceISA.Add(I); } catch (Exception e) { Console.WriteLine("Something horrible happenned:"); Console.WriteLine(e.Message); Console.WriteLine("Instruction skipped."); //throw e; } } } CheckSum = Convert.ToInt32(line.Substring(line.Length - BYTEBLOCK, BYTEBLOCK), 16); } return(sourceISA); }