🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Adventures in Assemblers

Published February 20, 2009
Advertisement
Epoch Q&A
Thanks for everyone who's posted for the Q&A. I'm still considering it open, so fire away with all those questions. See the post a couple days prior to this one for the current set of questions and answers.


Current Status
There's something I've wanted to do ever since I wrote the first EpochASM assembler - rewrite it completely. The implementation that shipped in R5 is pretty craptacular. It's literally a giant glob of if/else statements that test for each possible instruction and data combination.

What I've done is convert over to a table-driven assembler. The table basically amounts to a miniature language. Using #defines, the C++ compiler takes the assembler table and converts it to actual C++. This generated code then does the job of assembling (or disassembling) a program.

The generated code is nothing fancy - in fact, it's pretty much a carbon copy of the hand-written code, with some quirks due to the fact that it's all automatically generated. However, this is a major bonus for maintainability, because it's now trivial to add an instruction to the VM, and the assembler and disassembler automatically know how to work with it.

This leaves one piece that is still hand-coded, and that's the actual bytecode loader in the VM. Unfortunately, I can't think of a good way to automate that code, since it really all has to be capable of handling specific situations for each different instruction. There may be some low-hanging refactor fruit in there, though.


Only one problem with this grand adventure - the assembler quit working. Somewhere along the way I mistranslated a couple of rules, and now the disassembler and loader both fail to accept generated binaries. So my evening will consist of tearing apart the assembler again and trying to find exactly what went wrong.

Later on once things are working again I'll post up my current R6 to-do list.
0 likes 0 comments

Comments

Nobody has left a comment. You can be the first!
You must log in to join the conversation.
Don't have a GameDev.net account? Sign up!
Profile
Author
Advertisement
Advertisement