3 ms·
Writing an simple assembler is trivial. Even macro assemblers are very easy. However, it's also boring. Nevertheless the contents of the book cover all the te
by hdbxbxndj 2y ago
Writing an simple assembler is trivial. Even macro assemblers are very easy.
However, it's also boring.
Nevertheless the contents of the book cover all the techniques required to write an assembler, if you'd really like to
- alok-g 2y agoI understand that assembly file can be parsed in the same way. However, I want to learn about the machine instructions to the level of bits, and likewise the layouts of binary files. Unless I am able to go all the way to machine code loaded in memory, I would not know where in memory to add a breakpoint instruction when a developer wants the same on a line of code. If there is some library that can help create machine code from assembly instructions on a line by line basis (at least as opposed to invoking a separate program that generates the entire binary collectively from the assembly code), that could also work. In my case, I already know enough of the lexer, parser, etc., parts. What's missing is going all the way to making a debugger, profiler, etc.
- fuhsnn 2y ago>If there is some library that can help create machine code from assembly instructions on a line by line basis That's what JIT libraries do, for example asmjit: https://github.com/asmjit/asmjit/blob/master/test/asmjit_test_assembler_x64.cpp https://github.com/asmjit/asmjit/blob/master/test/asmjit_tes...
- rramadass 2y agoCheckout GNU Binutils and their usage of libbfd and libopcodes.
- jsnnsjxj 2y agoBuilding a debugger and profiler is quite an advanced task compared to building an assembler though ^^ Also much of that work is heavily dependent on the used operating system. Nevertheless, I'm wishing you all the best on your journey!
- peterfirefly 2y agoReally? You can get quite far just with ptrace() on Linux... and maybe something like system("nm xxxx > file") for the symbols.
- peterfirefly 2y agoThere can be weird interactions unless there are strong enough limits on what kind of expressions the assembler allows. Especially if it supports conditional assembly and loops in the macros. One ugly way around it -- which causes its own headaches -- is to introduce pass-sensitive conditional assembly (as in "if in pass 1/2/..."). It's also "fun" if some instructions come in different sizes... and you may need stronger restrictions on allowed expressions in that case.