I'm interested in writing an x86 assembler for a hobby project.
At first it seemed fairly straight forward to me but the more I read into it, the more unanswered questions I find myself having. I'm not totally inexperienced: I've used MIPs assembly a fair amount and I've written a toy compiler for a subset of C in school.
My goal is to write a simple, but functional x86 assembler. I'm not looking to make a commercially viable assembler, but simply a hobby project to strengthen my knowledge in certain areas. So I don't mind if I don't implement every available feature and operation.
I have many questions such as: Should I use a one-pass or two-pass method? Should I use ad-hoc parsing or define formal grammars and use a parser-generator for my instructions? At what stage, and how do I resolve the addresses of my symbols?
Given my requirements, can anyone suggest some general guidelines for the methods I should be using in my pet-project assembler?
It's just tedious to write Assembler using Assembly Language or even Machine Code. The purpose of this task is to understand how to translate Assembly Language to Machine Code, it's fine to use higher level language such as C, python, java etc as long as you understand the theory behind it.
Learn what a register is, then learn some basic instructions. There's about 20 to 30 instructions in the original x86 instruction set. Those original instructions are for really basic things like ADD, SUB, jumps, calling functions, etc. Learn those first because they're still the backbone of modern x86/x64.
There's nothing special about how an assembler is written. All it does is parse an assembly syntax and spit out machine code for a particular architecture. If your preferred programming language can read text and write binary, you can create an assembler with it.
It is used to produce object code for the x86 class of processors. Regarded as a programming language, assembly is machine-specific and low-level. Like all assembly languages, x86 assembly uses mnemonics to represent fundamental CPU instructions, or machine code.
There is an excellent free e-book (pdf) on how to build assemblers and loaders by David Salomon. You can find it at:
http://www.e-booksdirectory.com/details.php?ebook=1311
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With