S-Assembler v0.1 Release

The Savage State from The Course of Empire by Thomas Cole

Oh, wonder! How many goodly creatures are there here! How beauteous mankind is! O brave new world, that has such people in ‘t!

Yes, hello, welcome. Today I announce S-Assembler (sasm) version 0.1 codename “The Savage State”. Sasm is a self-hosting RiscV assembler. The bootstrap assembler was written in Rust. It is rather limited at this time, although it is capable of assembling itself. You can find the code on Github. I give an example:

1 (include! "syscalls.sasm")
2 (define message "Hello, world\n")
3 ;; write(stdout, message, message.len)
4 (addi x10 x0 STDOUT)
5 (la x11 message)
6 (addi x12 x0 (len message))
7 (addi x17 x0 SYS_WRITE)
8 (ecall)
9 ;; exit(0)
10 (addi x10 x0 0)
11 (addi x17 x0 SYS_EXIT)
12 (ecall)

For version 0.2 I will be adding a module system, improving error messages, and moving from arrays to vecs and array maps to a more efficient map, possibly some type of trie.


F.A.Q.

  • Q.
    Why would you do that?
    A.
    Fun things are fun

  • Q. How do I use this?

    A. Download the repository, build the bootstrap version in bootstrap/sasm, then run ../bootstrap/sasm/target/release/sasm sasm.sasm sasm in the sasm directory to build the self-hosting version. This should run under Linux on RiscV machines, although I don't have one to test on. On AMD64 Linux install qemu-user and you can now run the RiscV binaries as if they were native executables.


  • Q. How do the versions compare?

    A. They are functionally equivalent. The bootstrap version has slightly better error messages, although they're mostly useless. I intend to add actual error messages for version 0.2, although I'm not sure if I will add them to the bootstrap version. Both versions are self-contained. There are no dependencies beyond the Rust standard library.


  • Q. How big is this?

    A. The bootstrap version is 2171 SLOC and produces a 459 KB executable (this doesn't include libc). The self-hosting version is 2133 SLOC and produces a 8144 byte executable, less than 2% the size of the bootstrap! While I wasn't surprised to have a smaller executable, I was amazed to find that it was also less lines of code! Undoubtedly the Rust version has some extra bits that could be done away with (a result of being orphaned several times), but I would not expect it to be even remotely close. Remember that with the RiscV version I have no stdlib, it even includes its own malloc implementation.

    I'd really like to know why the Rust executable is so much larger. Yes, it has a few strings included for the error "messages", but not 450K of them. Frankly, it should be much smaller as many things that require several RiscV instructions can be accomplished with a single instruction on AMD64. Rust is pretty infamous for disrespecting users' hard drives though, I have many projects which are multiple GIGABYTES on disk, which is simply obscene.