private static Dictionary<string, ushort> GetLabels(IList<KeyValuePair<string, string[]>> sections, Dictionary<string, RegexOpcode[]> regexOpcodeDict, int offset)
{
Regex label = new Regex(@"^\s*([_a-zA-Z]\w+):");
var labels = new Dictionary<string, ushort>();
int pc = 0;
foreach (var section in sections)
{
var sectionName = section.Key;
var code = section.Value;
var regexOpcodes = regexOpcodeDict[sectionName];
pc = sectionName == "text" ? offset : int.Parse(sectionName.Substring(3, 2), NumberStyles.HexNumber);
for (int i = 0; i < code.Length; i++, pc++)
{
// If there is a label at the start of the line, add it and its position to the label dictionary
if (label.IsMatch(code[i]))
labels.Add(label.Match(code[i]).Groups[1].Value, (ushort) pc);
pc += regexOpcodes[i].BytesFollowing;
}
}
return labels;
}