Skip to content

Commit

Permalink
1. [TEST]::test for if and while cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
whtoo committed Oct 11, 2023
1 parent 4388fdf commit 75a5c0f
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 29 deletions.
64 changes: 40 additions & 24 deletions ep18/src/main/resources/t.vm
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()
print
halt
iconst 0
br main_0
main_0 :
halt
19 changes: 14 additions & 5 deletions ep20/src/main/resources/t.cymbol
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;
}

0 comments on commit 75a5c0f

Please sign in to comment.