private string DecodeASMSingle(uint line, uint pc, bool useRegAliases) { _illegalFlag = false; // Find the binary line and format //string binaryLine = ASMValueHelper.HexToBinary_WithLength(line, 32); //uint uBinaryLine = ASMValueHelper.BinaryToUnsigned(binaryLine); EncodingFormat encFormat = FormatHelper.FindFormatByBinary(line); // If we couldn't find the command, it's some kind of mystery! Either not included in // the encoding file, or an illegal instruction. if (encFormat == null) { _errorTextBuilder.AppendLine("WARNING: Unknown command: " + ASMValueHelper.UnsignedToHex_WithLength(line, 8).ToUpper()); return("unknown"); } string newFormat = encFormat.ExpandedFormat; string syntax = encFormat.Syntax; string formatBinary = encFormat.Binary; string newSyntax = syntax; // Loop through syntax field and replace appropriate values int regIndex = 0; int immedIndex = 0; string argValue = ""; //string binaryValue = ""; //string prevBinaryValue = ""; int numericValue = 0; int prevNumericValue = 0; int syntaxLength = syntax.Length; int newIndex = 0; for (int i = 0; i < syntaxLength; i++) { char c = syntax[i]; // If this is a register or immediate, find value to replace in the syntax for the decoding if (char.IsLetter(c)) { int metaType = ASMFormatHelper.FindElementMetaType(c); if (metaType == ASMElementMetaType.Register) { char lookupChar = ASMStringHelper.CreateRegisterChar(regIndex); //int vfpuRegMode = (c == ASMElementTypeCharacter.VFPURegister ? encFormat.VFPURegisterTypes[regIndex] : 0); switch (c) { case ASMElementTypeCharacter.PartialVFPURegister: argValue = DecodePartialVFPURegister(encFormat, line, regIndex, lookupChar); break; case ASMElementTypeCharacter.InvertedSingleBitVFPURegister: numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]); argValue = DecodeInvertedSingleBitVFPURegister(numericValue, encFormat.VFPURegisterTypes[regIndex]); break; case ASMElementTypeCharacter.VFPURegister: numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]); argValue = DecodeRegister(numericValue, c, useRegAliases, encFormat.VFPURegisterTypes[regIndex]); break; default: //int binaryIndex = newFormat.IndexOf(lookupChar); //binaryValue = binaryLine.Substring(binaryIndex, ASMRegisterHelper.GetEncodingBitLength(c)); numericValue = FindNumericArgValue(line, encFormat.RegisterPositions[regIndex], encFormat.RegisterIncludeMasks[regIndex]); argValue = DecodeRegister(numericValue, c, useRegAliases, 0); break; } regIndex++; } else if (metaType == ASMElementMetaType.Immediate) { char lookupChar = ASMStringHelper.CreateImmediateChar(immedIndex); int binaryIndex = newFormat.IndexOf(lookupChar); //prevBinaryValue = binaryValue; prevNumericValue = numericValue; int immedLength = encFormat.ImmediateLengths[immedIndex]; int hexLength = (immedLength + 3) / 4; //binaryValue = binaryLine.Substring(binaryIndex, immedLength); //numericValue = FindNumericArgValue(line, encFormat.ImmediatePositions[immedIndex], ASMValueHelper.GetIncludeMask(encFormat.ImmediateLengths[immedIndex])); numericValue = FindNumericArgValue(line, encFormat.ImmediatePositions[immedIndex], encFormat.ImmediateIncludeMasks[immedIndex]); switch (c) { case ASMElementTypeCharacter.SignedImmediate: argValue = DecodeSignedImmediate(numericValue, hexLength); break; case ASMElementTypeCharacter.UnsignedImmediate: argValue = DecodeUnsignedImmediate(numericValue, hexLength); break; case ASMElementTypeCharacter.BranchImmediate: argValue = DecodeBranchImmediate(numericValue, pc); break; case ASMElementTypeCharacter.JumpImmediate: argValue = DecodeJumpImmediate(numericValue, pc); break; case ASMElementTypeCharacter.DecrementedImmediate: argValue = DecodeDecrementedImmediate(numericValue, hexLength); break; case ASMElementTypeCharacter.ModifiedImmediate: argValue = DecodeModifiedImmediate(numericValue, prevNumericValue, hexLength); break; case ASMElementTypeCharacter.ShiftedImmediate: argValue = DecodeShiftedImmediate(numericValue, encFormat.ShiftedImmediateAmounts[immedIndex], hexLength); break; case ASMElementTypeCharacter.VFPUPrefixImmediate: argValue = DecodeVFPUPrefixImmediate(numericValue, encFormat.VFPUPrefixType); break; default: break; } immedIndex++; } // Replace character in syntax with correct value newSyntax = ASMStringHelper.ReplaceCharAtIndex(newSyntax, newIndex, argValue); newIndex += argValue.Length - 1; } newIndex++; } string spacing = string.IsNullOrEmpty(newSyntax) ? "" : " "; string decoding = encFormat.Command + spacing + newSyntax; if (_illegalFlag) { decoding = "illegal"; _errorTextBuilder.AppendLine(ASMStringHelper.Concat("Illegal instruction: ", line.ToString("x"), ": ", encFormat.Command.ToUpper(), " (", _illegalMessage, ")")); } return(decoding); }