AVR Bare Metal With Lisp

Spread the love

There are two kinds of programmers: those who don’t use Lisp, and those who need new parenthesis keycaps every six months. Lisp is one of those languages you either really love or really hate. If you love it, you may have checked out ulisp, which runs on Arduino boards of the AVR and ARM variety, as well as ESP chips, RISC-V, and others. A recent update allows the language to insert assembler into AVR programs.

We probably don’t need to convince anyone reading Hackaday why adding assembler is a good thing. It seems to integrate well with the environment, too, so you can write assembler macros in Lisp, which opens up many possibilities.

Of course, the format isn’t the same as your garden variety assembler. After all, Lisp should stand for “lots of irritating spurious parenthesis.” Plus your code needs to be position-independent since you’ll never know where it loads.

Here’s a simple example:

; Greatest Common Divisor
(defcode gcd (x y)
($movw 'r30 'r22)
($movw 'r22 'r24)
($movw 'r24 'r30)
($sub 'r30 'r22)
($sbc 'r31 'r23)
($br 'cs swap)
($br 'ne again)
(gcd 3287 3460)

There are more examples on the website, including direct I/O register manipulation.

We’ve seen badges running ulsip. Honestly, though, we’d be just as happy with Forth and it is easier on our parenthesis keys.

Source link

Leave a Reply

Your email address will not be published. Required fields are marked *