private void MakeAdressesForLabels(int programstart) { foreach (Tuple <int, string> offset in instructionIndicesToLabel) { uint instr = text[offset.Item1 / 4]; Instruction.Format f = Instruction.GetFormat(instr); if (f == Instruction.Format.I) { short iimediate = (short)((labelToAddr[offset.Item2] - offset.Item1) / 4); instr = Instruction.SetIImmediate(iimediate, instr); } else if (f == Instruction.Format.J) { int val = (programstart + labelToAddr[offset.Item2]) / 4; instr = Instruction.SetJImmediate(val, instr); } else { throw new Exception("WTF HAPPENED HERE???"); } text[offset.Item1 / 4] = instr; } }
void ExecuteInstruction(uint instr) { Instruction.Format format = Instruction.GetFormat(instr); switch (format) { case Instruction.Format.R: ExecuteRInstruction(instr); break; case Instruction.Format.I: ExecuteIInstruction(instr); break; case Instruction.Format.J: ExecuteJInstruction(instr); break; } }
private void MakeAdressesForData(int datastart) { foreach (Tuple <int, string> offset in instructionIndicesForData) { uint instr = text[offset.Item1 / 4]; Instruction.Format f = Instruction.GetFormat(instr); string name = offset.Item2; int iofbracket, upper = -1, lower = -1; if ((iofbracket = name.IndexOf('[')) > -1) { int icolon = name.IndexOf(":"); upper = Convert.ToInt32(name.Substring(iofbracket + 1, icolon - iofbracket - 1)); lower = Convert.ToInt32(name.Substring(icolon + 1, name.Length - icolon - 2)); name = name.Substring(0, iofbracket); } if (f == Instruction.Format.I) { int iimediate = datastart + dataToAddr[name]; if (iofbracket > 0) { //@HACK: not acctually using the real values if (upper == 31) { iimediate = iimediate >> 16; } else if (upper == 15) { iimediate = iimediate & 0x0000FFFF; } } instr = Instruction.SetIImmediate((short)iimediate, instr); } else { throw new Exception("WTF HAPPENED HERE???"); } text[offset.Item1 / 4] = instr; } }