public byte[] Assemble()
{
ICollection<AddressableInstruction> sourceTree = ParseSource();
AddressableInstruction lastInstruction = sourceTree.Last();
long binarySize = lastInstruction.Address.BinaryAddress + lastInstruction.BinaryLength;
// Create an array of the required size to hold the binary data.
// Size is taken from the final binary address used.
byte[] binary = new byte[binarySize];
// Assemble the binary for each instruction and store it in the array.
foreach (AddressableInstruction instruction in sourceTree)
{
byte[] instructionBinary = instruction.AssembleBinary();
Array.Copy(instructionBinary, 0, binary, instruction.Address.BinaryAddress, instruction.BinaryLength);
}
return binary;
}