-
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 <[email protected]>
- Loading branch information
1 parent
6bcae7e
commit f81517b
Showing
4 changed files
with
54 additions
and
1 deletion.
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,49 @@ | ||
static void putc(int); | ||
static void puti(int); | ||
static int fib(int); | ||
|
||
/* TODO: this sample fails to compile on higher -O values */ | ||
|
||
void _start(void) | ||
{ | ||
asm volatile ("law 04000"); | ||
asm volatile ("dac 209"); | ||
asm volatile ("law 03000"); | ||
asm volatile ("dac 208"); | ||
|
||
int n; | ||
|
||
for (int i = 0; i < 20; i++) { | ||
puti(fib(i)); | ||
putc(033); | ||
} | ||
|
||
asm volatile ("hlt"); | ||
__builtin_unreachable(); | ||
} | ||
|
||
static void putc(int c) | ||
{ | ||
asm volatile ("lio %0" : : "r"(c) : "io"); | ||
asm volatile ("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
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