private void SetBranchLabelAddressReferences() { foreach (ushort index in Branches.Keys) { string labelName = Branches[index]; if (!Scopes.ContainsLabel(labelName, index)) { throw new Exception($"Unknown label reference '{labelName}'"); } ushort label_address = (ushort)Scopes.LabelAddress(labelName, index); int delta = label_address - index; if ((delta & 0x00000001) != 00) { throw new Exception($"Branch to label '{labelName}' is not word aligned"); } delta /= 2; if ((delta > sbyte.MaxValue) || (delta < sbyte.MinValue)) { throw new Exception("Branch operation out of range"); } Code[index + 1] = (byte)((sbyte)delta); } }
private void SetLabelAddressReferences() { foreach (ushort index in Labels.Keys) { string labelName = Labels[index].ToLowerInvariant(); ushort offset = 0; GetLabelOffset(ref labelName, ref offset); if (Scopes.ContainsLabel(labelName, index)) { ushort address = (ushort)Scopes.LabelAddress(labelName, index); address += offset; Code[index] = (byte)(address & 0x00ff); Code[index + 1] = (byte)((address & 0xff00) >> 8); } else if (Scopes.ContainsAlias(labelName, index)) { ushort address = (ushort)Scopes.AliasAddress(labelName, index); address += offset; Code[index] = (byte)(address & 0x00ff); Code[index + 1] = (byte)((address & 0xff00) >> 8); } else { throw new Exception($"Unresolved label or alias: {labelName} with offset of {offset}"); } } }
private void SetDataFieldLabelAddressReferences() { foreach (ushort key in DataFields.Keys) { string labelName = DataFields[key].ToLowerInvariant(); if (Scopes.ContainsLabel(labelName, key) != true) { throw new Exception($"Unknown label '{labelName}' referenced in data field"); } ushort address = (ushort)Scopes.LabelAddress(labelName, key); Code[key] = (byte)(address & 0x00ff); Code[key + 1] = (byte)((address & 0xff00) >> 8); } }