by pounce » Mon Oct 10, 2011 6:37 am
I wrote a 8051 assember in Lisp- I took the approach of trying to "lisp-ify" the usual assembly language; ie make a domain-specific language using Lisp. So I built up "lispy" definitions of all the mnemonics, which when evaluated by the assembler, emit the 8051 machine code. There are also the usual dw, db etc directives. So essentially, a program is written using the native assembly mnemonics, but in Lisp as the sample program shows below;
(defproject testproj
(:text-base #x100
:data-base nil
:text-align 16
:data-align 8))
(defmacro xyzpdq (parm)
`(add acc ,parm))
(defparameter +RESERVE-DATA-LEN+ 100)
(defdata tst-data2 (:org #x20)
(dw '*text-start* '*text-end* '(- *text-end* *text-start*))
(dw '*data-start* '*data-end* '(- *data-end* *data-start*))
(dw '*bss-start* '*bss-end* '(- *bss-end* *bss-start*))
(dw 'tst-code))
(defbss tst-bss ()
(reserve +RESERVE-DATA-LEN+))
(defdata tst-data ()
(dw 0 1 2 3 'tst-code 'tst-bss)
(db 4 5 6 7 '(lobyte tst-data2))
(db \"hello, world\")
supercat2
(filldata +RESERVE-DATA-LEN+)
(filldata 10 #\\x)
(filldata 2 '(let ((x 1) (y 2) (z 3))
(list x y z))) )
(deftext tst-code ()
(nop)
(xyzpdq 10)
(nop)
supercat
(addc a 1)
(anl acc 15)
(inc dptr)
(cjne acc 3 'tst-data)
(clr a)
(asm51symbols:push acc)
(asm51symbols:pop acc)
(ajmp 'supercat2)
(acall 'supercat)
(acall 'tst-data)
(acall '(+ tst-code 2)))" )
A big win is being able to use Lisp's macro syntax to build up program structure. The assembler is multi-pass so forward declarations etc are OK, and a desk-check of the output machine code looks OK but I haven't run it yet. As you can see with push/pop I have namespace problems.. probably I should dig into that a bit more- in this case there is a collision w/ Lisp's functions of the same name- OTOH I want the usual Lisp functions available for macros etc but that leads to the symbol collision. An easy solution would be to put some extra syntax on the 8051 mnemonics so the collision doesn't occur- maybe an underscore or something.
Project is open source- would be happy to give out the source code but I've not posted it anywere..
Greg