4 ms·
I think this is just half true. When dealing with purely high-level code (including C without inline assembly), the compiler doesn't need a discrete assembler.
by kbolino 1y ago
I think this is just half true.
When dealing with purely high-level code (including C without inline assembly), the compiler doesn't need a discrete assembler. This much is true, and most modern compilers will not spit out assembly unless requested.
However, there's usually still a stage of the compilation process where an assembly-like internal representation is used. Once the compiler has chosen which registers to use and where, and which instructions to use and in what order, etc., it's close to machine code but not fully there yet. At this point, jump targets will still be labels without concrete addresses, instructions will be still be referenced by mnemonic, etc.
Serializing this internal representation as assembly will generally produce more readable code than disassembling the final binary. So it's not assembly exactly, but it's pretty close.
- Stratoscope 1y agoYes, very true! And more accurate than what I wrote. The point I meant to make was that assembly language in the text form that we would use is not part of the compilation process. But I oversimplified my description rather badly. Interestingly, Go also has a -d=ssa/all switch that outputs not just an assembly representation of the final code, but also the results of each optimization pass. Here is a discussion I had with ChatGPT about this: https://chatgpt.com/share/6859aea5-df1c-8012-be70-f2361060fb5b https://chatgpt.com/share/6859aea5-df1c-8012-be70-f2361060fb...