top | item 46908883

(no title)

TheCondor | 24 days ago

The assembler seems like nearly the easiest part. Slurp arch manuals and knock it out, it’s fixed and complete.

discuss

order

jakewins|24 days ago

I am surprised by the number of comments that say the assembler is trivial - it is admittedly perhaps simpler than some other parts of the compiler chain, but it’s not trivial.

What you are doing is kinda serialising a self-referential graph structure of machine code entries that reference each others addresses, but you don’t know the addresses because the (x86) instructions are variable-length, so you can’t know them until you generate the machine code, chicken-and-egg problem.

Personally I find writing parsers much much simpler than writing assemblers.

nicebyte|24 days ago

assembler is far from trivial at least for x86 where there are many possible encodings for a given instruction. emitting the most optimal encoding that does the correct thing depends on surrounding context, and you'd have to do multiple passes over the input.

jmalicki|21 days ago

All you have to do is record a table of fixup locations you can fill in in a second pass once the labels are resolved.

shakna|24 days ago

Huh. A second person mentioning the assembler. Don't think I ever referred to one...?