mirror of
https://github.com/janet-lang/janet
synced 2025-04-26 20:53:12 +00:00
commit
0db83bd787
@ -1,10 +1,10 @@
|
|||||||
# Example of dst bytecode assembly
|
# Example of dst bytecode assembly
|
||||||
|
|
||||||
# Fibonacci sequence, implemented with naive recursion.
|
# Fibonacci sequence, implemented with naive recursion.
|
||||||
(def fibasm (asm '{
|
(def fibasm
|
||||||
arity 1
|
(asm
|
||||||
bytecode [
|
'{:arity 1
|
||||||
(ltim 1 0 0x2) # $1 = $0 < 2
|
:bytecode @[(ltim 1 0 0x2) # $1 = $0 < 2
|
||||||
(jmpif 1 :done) # if ($1) goto :done
|
(jmpif 1 :done) # if ($1) goto :done
|
||||||
(lds 1) # $1 = self
|
(lds 1) # $1 = self
|
||||||
(addim 0 0 -0x1) # $0 = $0 - 1
|
(addim 0 0 -0x1) # $0 = $0 - 1
|
||||||
@ -16,8 +16,7 @@
|
|||||||
(add 0 0 2) # $0 = $0 + $2 (integers)
|
(add 0 0 2) # $0 = $0 + $2 (integers)
|
||||||
:done
|
:done
|
||||||
(ret 0) # return $0
|
(ret 0) # return $0
|
||||||
]
|
]}))
|
||||||
}))
|
|
||||||
|
|
||||||
# Test it
|
# Test it
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user