-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Filip Kokosiński <filip.kokosinski@gmail.com>
- Loading branch information
1 parent
6bcae7e
commit 2a53104
Showing
3 changed files
with
49 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../common/common.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
static void putc(int); | ||
static void puti(int); | ||
static int fib(int); | ||
|
||
void _start(void) | ||
{ | ||
asm ("law 04000"); | ||
asm ("dac 209"); | ||
asm ("law 03000"); | ||
asm ("dac 208"); | ||
|
||
int n; | ||
|
||
for (int i = 0; i < 20; i++) { | ||
puti(fib(i)); | ||
putc(033); | ||
} | ||
|
||
asm ("hlt"); | ||
__builtin_unreachable(); | ||
} | ||
|
||
static void putc(int c) | ||
{ | ||
asm ("lio %0" : : "r"(c)); | ||
asm ("tyo"); | ||
} | ||
|
||
/* TODO: this is printing out digits in reverse order; fix it */ | ||
static void puti(int i) | ||
{ | ||
int mod; | ||
|
||
do { | ||
mod = i % 10; | ||
putc((mod == 0) ? 020 : mod); | ||
i /= 10; | ||
} while (i != 0); | ||
} | ||
|
||
static int fib(int n) | ||
{ | ||
if (n <= 1) | ||
return n; | ||
else | ||
return fib(n - 1) + fib(n - 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters