-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. [TEST]::test for if and while cases.
- Loading branch information
Showing
2 changed files
with
54 additions
and
29 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 |
---|---|---|
@@ -1,32 +1,48 @@ | ||
.def fib: args=1 ,locals=1 | ||
load 0 | ||
iconst 2 | ||
ile | ||
brt fib_0 | ||
br fib_1 | ||
fib_0 : | ||
.def fib: args=1 ,locals=4 | ||
iconst 1 | ||
ret | ||
br fib_2 | ||
store 1 | ||
iconst 1 | ||
store 2 | ||
iconst 1 | ||
store 3 | ||
fib_1 : | ||
load 3 | ||
load 0 | ||
ile | ||
brt fib_2 | ||
br fib_3 | ||
fib_2 : | ||
load 1 | ||
store 4 | ||
load 1 | ||
load 2 | ||
iadd | ||
store 2 | ||
load 4 | ||
store 1 | ||
load 3 | ||
iconst 1 | ||
isub | ||
call fib() | ||
load 0 | ||
iconst 2 | ||
isub | ||
call fib() | ||
iadd | ||
store 3 | ||
load 1 | ||
iconst 20 | ||
ige | ||
brt Local_Local_fib_0 | ||
br Local_Local_fib_2 | ||
Local_Local_fib_0 : | ||
load 1 | ||
br fib_0 | ||
Local_Local_fib_2 : | ||
br fib_1 | ||
fib_3 : | ||
fib_0 : | ||
load 3 | ||
ret | ||
br fib_2 | ||
fib_2 : | ||
|
||
|
||
.def main: args=0 ,locals=1 | ||
iconst 0 | ||
store 0 | ||
iconst 8 | ||
.def main: args=0 ,locals=0 | ||
iconst 10 | ||
call fib() | ||
halt | ||
iconst 0 | ||
br main_0 | ||
main_0 : | ||
halt |
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 |
---|---|---|
@@ -1,12 +1,21 @@ | ||
|
||
int fib(int n){ | ||
if (n <= 2) { return 1; } | ||
else { return fib(n-1) + fib(n-2); } | ||
int p = 1; | ||
int q = 1; | ||
int c = 1; | ||
while(c <= n) { | ||
int tmp = p; | ||
q = p + q; | ||
p = tmp; | ||
c = c + 1; | ||
if (p >= 20) { return p; } | ||
} | ||
} | ||
|
||
|
||
void main() { | ||
int i = 0; | ||
print(fib(5)); | ||
int main() { | ||
|
||
print(fib(10)); | ||
return 0; | ||
} | ||
|