Hi,

On linux, x86-64 I can now write,

(use-modules (native aschm))

(define b (asm
           (inst mov rbx 1000000000) ;rbx = 1000,000,000
          loop:
           (inst cmp rbx 0)
           (inst jmp #:eq out:)
           (inst dec rbx)
           (inst jmp loop:)
          out:
           (inst mov rax 2)          ; return value in register rax
           (inst pop rbx)            ; we pushed the return adress before
           (inst jmp rbx)))          ; jump back

(mk-rwx b)                           ; Make the memory pages read write and
                                     ;   execute

(run-native b)                       ; run the code using a simple scheme

And the code loops and return 0 (2).

So it is possible to generate assembler from whithin guile and execute it
which is pretty cool.

If you have the right architecture, you can play with it at:

https://gitorious.org/aschm

Have fun
Stefan

Reply via email to