Lisp as assembly language??

Whatever is on your mind, whether Lisp related or not.
Posts: 20
Joined: Sat Aug 20, 2011 6:49 pm

Re: Lisp as assembly language??

Post by adam33147 » Mon Sep 12, 2011 3:51 pm

I find this a fascinating subject. But there seem to be so many dead ends. Here is a page I found some time back with Lisp OSes. There are many dead projects mixed in if I remeber correctly.

This one seems very interesting.
"The Movitz system aspires to be an implementation of ANSI Common Lisp that targets the ubiquitous x86 PC architecture "on the metal". That is, running without any operating system or other form of software environment. Movitz is a development platform for operating system kernels, embedded, and single-purpose applications. There can potentially be several completely different operating systems built using Movitz."

Common Lisp on the metal would be an example of Common Lisp as Assembly, no? Project hasn't been posted to in years though.

Posts: 1
Joined: Mon Oct 10, 2011 5:16 am

Re: Lisp as assembly language??

Post 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\")
(filldata +RESERVE-DATA-LEN+)
(filldata 10 #\\x)
(filldata 2 '(let ((x 1) (y 2) (z 3))
(list x y z))) )

(deftext tst-code ()
(xyzpdq 10)
(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..


Posts: 17
Joined: Fri Oct 28, 2011 3:41 pm

Re: Lisp as assembly language??

Post by virex » Sat Oct 29, 2011 2:19 pm

If you're working in a self-defined package, you could also shadow those functions, which would allow you to access them with CL:push and CL:pop.

Post Reply