PASM (Portable ASeMbler)
PASM (Portable ASeMbler) was written long ago when I was obsessed with compilers. I wanted to show that you could abstract away the hardware specific parts of a JIT (Just In Time compiler) into an API that was simple enough for most people to use. I think that I had one person using it at the time, at least that emailed me and said so. I never found out what it was for though, just that it was running under BeOS.
It is comprised of two layers. Firstly a set of C macros that represent assembly directives, with parameters, and emit bytes to a buffer. Secondly a set of API methods written in terms of simple primitives that can be used to express an algorithm. There was no optimization, everything was kept simple. The API allowed you to declare variable slots on the stack, and operate on them using the provided primitives. In terms of generated code it was riddled with loads and stores.
Frankly to get that far was great. The next step would have been to push the code generation layer into a service module, so that other service modules could be written for other architectures, or sub-architectures on the same platform. Then I would have liked to add some simple register optimization.
I wasn’t going for speed records, just good performance and reliable results.
I’m making it available again in the hope that somebody will decide to use it, or pick it up and develop it further. As of right now I really don’t have the time, and see little benefit. That said, I am still proud of it, and want it to live on.
Things to note.
- Originally this code was compiled with -O2 on GCC. When I dug it out again recently, I found that the test suite failed at -O2. It’s not the code produce by PASM that was wrong, it was the C code against which I was testing.. No really!!… OK, so I have pushed it down to -O1, so that the compiler will now continue to be a good benchmark for comparison.
- The type system used is architecture independent. Long is 64 bit and int is 32 bit, always. This was intentional so that the coder does not need to worry about architecture, and can concentrate on application logic.
- Think you can read C. Try reading macros!… x86.h contains all of the macros for i386 assembly, and test.c will stress test any compiler.
- I have made the decision to switch from the original forgiving copyright to LGPL. That’s actually not bad, as LGPL is pretty forgiving, but it does ensure that this software will remain free.
Download the software from here and a sample program here.
Instructions are in the pasm folder. Additionally I have added a sample program to get you started, that shows just how easy it is to JIT using PASM.