Fragment Assembly is fairly straight forward in theory: you have several pieces of data, then you stick them together. However some file formats are tricky. One such difficult concept is the label.
In a typical assembler you might be able to declare a label as follows.
mov %rax, %rnx
ret
this_is_a_label:
mov %rbx, %rcx
The meaning of a label is fairly straightforward: each label represents a relative position within the generated file. In the above example, the inserted label may be referenced from somewhere else in the file. The label itself does not occupy space. Space is occupied by references to the label.
Algorithmically, it is straightforward to generate labels in two passes. The first pass concatenates data, takes note of label references that need to be fixed, and calculates actual positions of labels relative to the start of the file. The second pass can jump around to each label reference and insert the calculated value. This is perhaps the most complicated feature of a typical assembler, though it isn’t terribly complicated.