2 ms·
I compiled a basic C program and then read the output of GCC -S to see the assembly. I used what I learned from GCC output Then I wrote a basic amd64 expressio
by samsquire 4y ago
I compiled a basic C program and then read the output of GCC -S to see the assembly.
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 https://github.com/samsquire/compiler
or on replit:
https://replit.com/@Chronological/Compiler3#main.py https://replit.com/@Chronological/Compiler3#main.py
Finding opcodes is a struggle but there is this website:
https://www.felixcloutier.com/x86/ https://www.felixcloutier.com/x86/
and
https://www.cs.uaf.edu/2016/fall/cs301/lecture/09_28_machinecode.html 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-control https://github.com/samsquire/multiversion-concurrency-contro... in ProgramParser.java, LanguageInterpreter.java, and LanguageInterpreterRunner.java for where main() is.
- JonChesterfield 4y agoIntel's documentation covers encoding. I remember it being relatively heavy going to decipher, been a few years since I've worked on x64 though.