I’m having some trouble parsing assembly efficiently. I read https://www.cs.tufts.edu/comp/150VM/modules/04asm.html, but I don’t like the approach of parsing assembly files twice for label resolution.
I think I may have found a solution that would allow me to parse the file in a single pass. My idea is to read through the file and, whenever the assembler encounters a label, add it to a hashmap (even with a bad hashing algorithm like a sum of characters). When it encounters a jump to an undefined label (i.e., one not yet in the hashmap), it would store a structure containing the requested label and its position in a list. Then, whenever a new label is defined, I would iterate over that list to resolve any pending references.
This approach should be faster, especially for large files.
Additionally, does it make sense to use traditional parsing techniques such as ASTs and lexers for assembly? Wouldn’t that be somewhat overkill and unnecessary, given how simple assembly syntax is?