60 lines
1.0 KiB
C
60 lines
1.0 KiB
C
str terminal_namespace = "/dev/term/0";
|
|
str new_line = "\n";
|
|
|
|
function main () {
|
|
int result;
|
|
int str_n;
|
|
|
|
load_immediate 35 -> result;
|
|
call fib (result) -> result;
|
|
int_to_string result -> str_n;
|
|
call pln (str_n);
|
|
exit 0;
|
|
}
|
|
|
|
function fib (int n) {
|
|
int result;
|
|
load_immediate 2 -> result;
|
|
|
|
jump_lt_int base_case n result;
|
|
|
|
int two;
|
|
int tmp_n;
|
|
int result_a;
|
|
int result_b;
|
|
|
|
load_immediate 2 -> two;
|
|
sub_int n two -> tmp_n;
|
|
call fib (tmp_n) -> result_a;
|
|
|
|
int one;
|
|
load_immediate 1 -> one;
|
|
sub_int n one -> tmp_n;
|
|
call fib (tmp_n) -> result_b;
|
|
|
|
add_int result_b result_a -> result;
|
|
return result;
|
|
|
|
else base_case;
|
|
return n;
|
|
}
|
|
|
|
function pln (str message) {
|
|
ptr term;
|
|
int msg_length;
|
|
str nl;
|
|
int nl_length;
|
|
int mode;
|
|
str term_ns;
|
|
|
|
load_immediate 0 -> mode;
|
|
load_address terminal_namespace -> term_ns;
|
|
syscall OPEN term_ns mode term;
|
|
string_length message -> msg_length;
|
|
syscall WRITE term message msg_length;
|
|
load_address new_line -> nl;
|
|
string_length nl -> nl_length;
|
|
syscall WRITE term nl nl_length;
|
|
return;
|
|
}
|