3 ms·
I know this article is about bootloaders but more generally there are two ways I've tackled x86 as a total noob: compile a simple language to like ~5 instructio
by eatonphil 5y ago
I know this article is about bootloaders but more generally there are two ways I've tackled x86 as a total noob: compile a simple language to like ~5 instructions [0, 1] and, separately, write an emulator for ~5 instructions that can run basic C programs [2, 3].
I think it's fairly common to recommend beginners to write a compiler but I think it's less common to actually recommend trying to emulate parts of x86. I think it's a particularly easy way to get started just because it's the architecture you already know or because its the architecture that all compiler tutorials use (if they don't use LLVM). And if you are a programmer you probably incidentally have gcc, gdb, and objdump on your system ready to help you out.
Doing both compilers _and_ emulators really helped my understanding of x86 and C (even if I wasn't writing C).
My background is in web development and my reason for doing these projects/writing is purely educational.
[0] https://notes.eatonphil.com/compiler-basics-lisp-to-assembly.html https://notes.eatonphil.com/compiler-basics-lisp-to-assembly...
[1] https://notes.eatonphil.com/compiler-basics-an-x86-upgrade.html https://notes.eatonphil.com/compiler-basics-an-x86-upgrade.h...
[2] https://notes.eatonphil.com/emulating-amd64-starting-with-elf.html https://notes.eatonphil.com/emulating-amd64-starting-with-el...
[3] https://notes.eatonphil.com/emulator-basics-a-stack-and-register-machine.html https://notes.eatonphil.com/emulator-basics-a-stack-and-regi...
- secondcoming 5y agoCompiler Explorer [0] is a godsend for seeing what the compiler is generating. For example, the codegen for some C++ that was discussed a few days ago [1] [0] https://godbolt.org/ https://godbolt.org/ [1] https://godbolt.org/z/cfYKqajMd https://godbolt.org/z/cfYKqajMd
- nvarsj 5y agoDoing CTFs is also a way to get intimately familiar with x86 assembly, and they are pretty fun too.
- iota8 5y agoHere is an article that explains how C code is translated into assembly: https://www.avabodh.com/cin/cin.html https://www.avabodh.com/cin/cin.html This website also has another article which explains how a C++ code can be understood in terms of C code. https://www.avabodh.com/cxxin/cxx.html https://www.avabodh.com/cxxin/cxx.html
- rajeevk 5y agoHere is my article that explains how C code can be understood in terms of assembly: https://www.avabodh.com/cin/cin.html https://www.avabodh.com/cin/cin.html I also wrote another article which explain how C++ code can be understood in terms of C code: https://www.avabodh.com/cxxin/cxx.html https://www.avabodh.com/cxxin/cxx.html