1
1
mirror of https://github.com/anoma/juvix.git synced 2024-12-12 14:28:08 +03:00
juvix/tests/Asm/positive/test013.jva

47 lines
620 B
Plaintext
Raw Normal View History

2022-09-29 18:44:55 +03:00
-- tail recursion: compute the n-th Fibonacci number in O(n)
function fib'(integer, integer, integer) : integer {
push arg[0];
push 0;
eq;
br {
true: { push arg[1]; ret; }
false: {
2022-12-06 13:33:20 +03:00
push 16777216;
2022-09-29 18:44:55 +03:00
push arg[2];
push arg[1];
add;
2022-12-06 13:33:20 +03:00
mod;
2022-09-29 18:44:55 +03:00
push arg[2];
push 1;
push arg[0];
sub;
tcall fib';
}
};
}
function fib(integer) : integer {
push 1;
push 0;
push arg[0];
tcall fib';
}
function main() {
push 10;
call fib;
trace;
pop;
push 100;
call fib;
trace;
pop;
push 1000;
call fib;
trace;
pop;
push void;
ret;
}