This post is archived and probably outdated.

Extending PHP using Assembler

2006-11-21 00:58:00

While going through some old backups I found some funny stuff I did back in the times when I was a bit bored (or maybe just frustrated?) A PHP extension written using mostly Assembler instead of C.

If you are interested in scary and useless stuff you can fetch the code and try it. There is some C code in it to create two required structures (which makes no sense doing in assembler imo - while this doesn't mean that thing makes any sense) but all functions and everything else is done using Assembler in the nasm syntax for 32bit x86 machines. If you really want to try t you need nasm and a PHP built environment. After running phpize and configure, just as for any other extension, you might need to edit the Makefile holding two rules for the .s file (remove the one using gas as assembler)

The extension exports a single function confirm_asmext_compiled() which prints some stuff using PHP's output mechanism and returns an integer, which is a bit tricky using Assembler since from the C perspective the return value is returned using some zval * structure passed by reference (making it a zval **) to the function so you need to dereference it and need to check/find out how the C compiler arranges the zval structure...

Yes for doing such a thing you have to be real bored (or maybe just extremly frustrated....) I'm happy this being a few years ago but I wanted to archive it somewhere :-)