DEV Community


Writing an Assembler in Rust, and Why the Build Keeps Failing

Ashton Scott Snapp
Updated on ・2 min read

First off, I feel like the second part of the title is something pretty much every developer has experienced at one point. Second, obligatory GitHub repository plug:

GitHub logo AshtonSnapp / chasm

The Official Cellia Cross-Assembler for Modern Computers


Rust Build & Test

The Official Cellia Cross-Assembler for Modern Computers

Building chasm

Clone this repository to your local machine, cd into the chasm directory, and run cargo build. Simple!

Did a few things since last post. First, I set up a GitHub actions workflow that will build and test the project every time someone commits. Right now, I'm the only person working on this. Sadly. Second, I've implemented a variant for instructions and an enum that contains literally every single instruction in the architecture, all 51 of them, and four different callback functions for determining what instruction a token is.

Then I had to give directives higher priority because logos was getting confused, and I also made roughly too many regexps for addresses and immediates because of how callbacks work, and also because the architecture has 7 different addressing modes and I want to allow decimal, hexadecimal, and binary numbers for both addresses and immediates. 7 addressing modes plus two sizes for immediates, multiplied by 3 bases, means 27 regexps for addresses and immediates alone. I haven't even made the callbacks yet, which all those will do is make sure it's a valid number.

And now, I have an interesting... problem whenever I try to compile the program. This issue only popped up recently, after the previous post, meaning something changed for some god dang reason, and now I'm getting E0277: the size for values of type [u8] cannot be known at compilation time, and the error is pointing out the logos derive bit, followed by a line inside logos::lexer::Lexer. Why is this happening? I have no idea what I did that caused this, but whatever it was happened some time between the last post and this one!

Honestly, at this point, I should probably go over to the logos repository and make an issue because I have no idea what caused this or how to fix it. Well, until next time, have an awesome day. Because I most certainly am not having an awesome day.

Discussion (2)

newcombl profile image
Luke Newcomb

Hey! Just want to mention that you're not exactly alone in creating an assembler in Rust. Yours might be a little bit more... err.... useful. But if you'd like to talk about it, I think that would be great.

ashtonsnapp profile image
Ashton Scott Snapp Author

The second you mentioned it I had to go look at your Github. It's certainly interesting, I've never played Kerbal Space Program but I have seen videos and know how good a game it is, and I never knew someone made a KerbalOS for the game!

The most interesting part is that you're doing it all from scratch, mostly. I tried that when I started this project, and it didn't end so well - even when it compiled, it didn't work. Hence why I've moved over to using the logos library. Yet your project appears to be working (and far ahead with a preprocessor and parser).

I feel like I've rambled for a bit too long here. I'll be updating this series sometime today however, as I've gotten it to compile (finally!), though there are still going to be some issues that I'll have to work out, at least most likely. Good luck to your project!