Lisp HUG Maillist Archive

LW: The ultimate Assembly Code Breadboard?

Can Lispworks do this?

http://www.pvk.ca/Blog/2014/03/15/sbcl-the-ultimate-assembly-code-breadboard/

    Thanks, Joel

-- 
for hire:Erlang/OTP hacker
http://wagerlabs.com/about

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Re: LW: The ultimate Assembly Code Breadboard?

> Can Lispworks do this?
> http://www.pvk.ca/Blog/2014/03/15/sbcl-the-ultimate-assembly-code-breadboard/

What do you mean? Generate code from within LW and execute it?

I tried a couple of year ago to do this, it was (andd still is)
possible. I even wrote my simple assembler for LW.

Here is the main idea for LW 32 bits. The main CL function is add-1.
Based on this idea and the LW docs you can write you own assembler and
run machine code from within LW.


#|

add-one:

55               push ebp              (push epb)
89E5             mov ebp,esp           (mov ebp esp)
8B4508           mov eax,[ebp+$08]     (mov eax (+ ebp 8))
40               inc eax               (inc eax)
89EC             mov esp,ebp           (mov esp ebp)
5D               pop ebp               (pop ebp)
C3               ret                   (ret)

|#

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(fli:define-foreign-funcallable call-with-int
    ((value :int))
  :result-type :int)


(setq add-one-code '(#x55 #x89 #xE5 #x8B #x45 #x08 #x40 #x89 #xEC #x5D
#xC3))

(setq add-one-code-ptr (fli:allocate-foreign-object :type :uint8
                                                    :nelems (length
                                                    add-one-code)
                                                    :initial-contents
                                                    add-one-code))

(defun add-1 (n)
  (call-with-int add-one-code-ptr n))

_______________________________________________
Lisp Hug - the mailing list for LispWorks users
lisp-hug@lispworks.com
http://www.lispworks.com/support/lisp-hug.html


Updated at: 2020-12-10 08:34 UTC