Hi fellow coders.

I'm working on a dotnet library and I need help. Huh! dotnet!? Yes, but this dotnet library is a x86/x64 assembler! You may think of it as a part of a compiler back-end. In fact, it's exactly what it is!

A bit of code worth a thousand words, so here is the thing in action :

using System.IO;
using ArchAssembler.PortableExecutable;
using ArchAssembler.Elements;
using ArchAssembler.X86;

public static class Program
    public static void Main()
        // image
        var image = new Image32();
        image.Subsystem = ImageSubsystem.Windows;

        // code section
        var codeSection = new ImageSection(".text", ImageSectionType.Code);
        // readonly data section
        var dataSection = new ImageSection(".data", ImageSectionType.ReadonlyData);

        // import table
        var importTable = new ImportTableElement();
        image.Directories = importTable;

        // imported functions
        var exitProcessFunction = importTable.Import("KERNEL32.DLL", "ExitProcess");
        var messageBoxFunction = importTable.Import("USER32.DLL", "MessageBoxA");

        // strings
        var message = dataSection.VariableSizeString("Hello, world!");
        var caption = dataSection.VariableSizeString("Hum...");

        // main
        var main = codeSection.ElementCollection();
        image.EntryPoint = main;

        main.Call32(new EffectiveAddress(messageBoxFunction));
        main.Call32(new EffectiveAddress(exitProcessFunction));

        // let's do it!
        Stream stream = new FileStream("hello.exe", FileMode.Create, FileAccess.Write);
        image.Assemble(new BinaryWriter(stream));

It's called ArchAssembler, being a part of a larger project called Arch.

So, what kind of help do I need?

In fact, I would love to see people get involved with it.

There is still a lot of thing to do:

- X64 instructions
- SSE instructions
- PDB file
- Documentation and example
- Testing
- ...

Or maybe you have this cool idea that require an assembler library and you're interested in using this one.

Or simply to review it and comment.

Anyway, here is the CodePlex hosting if you're curious : http://archassembler.codeplex.com/

Many thanks!
Posted on 2011-05-17 14:30:49 by OddCode
Planning on writing a parsing frontend, or just the code-emitting backend?
Posted on 2011-05-18 18:26:04 by f0dder
Sounds like a .NET version of SoftWire?
Could be interesting.
Posted on 2011-05-18 18:34:04 by Scali
"parsing frontend" is a bit misleading, as there is no parsing involved in my programming language project (the AST is edited directly with specialized editors and saved in a database file), but yes, various levels of frontend are planned.

Never heard of SoftWire. The project looks dead, isn't it? Too bad, the source code could have been interesting.
Posted on 2011-05-19 02:26:56 by OddCode
Ah yes, apparently he removed all the source code, after he joined TransGaming. I knew he removed the SwiftShader code, but didn't assume he also removed SoftWire itself.
Basically he had a software implementation for Direct3D9 rendering, SwiftShader, which used SoftWire to dynamically compile shaders and generate optimized SSE code.
SoftWire could be used separately as a runtime assembler. This seems to be exactly what you're going to do.

You're in luck though: I helped him to debug some shaders and set up an example project back in the day. I still have a copy of the code from when it was open source (LGPL license):
This is the full Direct3D renderer, but it also includes the SoftWire code. Might be of use to you.
Posted on 2011-05-19 03:25:07 by Scali
Pretty much the same project indeed, even if SoftWire is more "runtime assembler" oriented (ligthweight, no PE support).
It's really interesting to see how he handled some of the problems I've faced.
The register allocation part need further reading but look promising.

Posted on 2011-05-19 07:20:12 by OddCode
Be careful if you look at the code, though, considering it's LGPL - you don't want to borrow too many ideas and risk that awful license infecting your own work :)
Posted on 2011-05-19 11:39:49 by f0dder

Be careful if you look at the code, though, considering it's LGPL - you don't want to borrow too many ideas and risk that awful license infecting your own work :)

I think the fact that he's using .NET is a perfect loophole here :)
(L)GPL deals only with copying the actual sourcecode. If you translate it in a different language, you haven't copied any of the original code.
If it was a software patent, it'd be different, since that would apply to the concept. But none of this code is patented.
Posted on 2011-05-19 11:46:25 by Scali