Re:CS 6120: Advanced Compilers: The Self-Guided Online Course
by JonChesterfield on Tuesday March 14, 2023 @09:20AM
(#35151000)
Intel's documentation covers encoding. I remember it being relatively heavy going to decipher, been a few years since I've worked on x64 though.
I used what I learned from GCC output Then I wrote a basic amd64 expression compiler with simple live ranges and linear register allocation and ANF (a normal form) for postorder AST traversal for code generation. It can only evaluate nested add and mul expressions.
https://github.com/samsquire/compiler or on replit: https://replit.com/@Chronological/Compiler3#main.py
Finding opcodes is a struggle but there is this website: https://www.felixcloutier.com/x86/ and https://www.cs.uaf.edu/2016/fall/cs301/lecture/09_28_machine... (the table at the bottom is really useful)
To learn code generation not targeting amd64, I wrote an imaginary assembly language and then wrote a switch based virtual machine and a compiler for it with a frontend that looks similar to javascript.
https://github.com/samsquire/multiversion-concurrency-contro... in ProgramParser.java, LanguageInterpreter.java, and LanguageInterpreterRunner.java for where main() is.