Skip to content

Commit a11aad0

Browse files
tofergreggCS107E BOT
authored andcommitted
Merge branch 'master' of github.com:cs107e/mango-staff
commit 236952458a4ffbdc39f67ef9ce4ec9f4d1748541 Author: Chris Gregg <[email protected]> Date: Fri Jan 10 09:48:16 2025 -0800 Merge branch 'master' of github.com:cs107e/mango-staff
1 parent 325275d commit a11aad0

File tree

5 files changed

+48
-0
lines changed

5 files changed

+48
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#include<stdio.h>
2+
#include<stdlib.h>
3+
4+
int main() {
5+
int n = 10; // number of fibonacci terms
6+
int f0 = 0; // fibonacci number (1st term)
7+
int f1 = 1; // fibonacci number (2nd term)
8+
while (n > 0) {
9+
printf("%d\n", f0); // print the current term
10+
int nth = f0 + f1; // the nth term
11+
f0 = f1; // update first
12+
f1 = nth; // update second
13+
n--; // decrement number of terms left
14+
}
15+
return 0;
16+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
n = 10 # number of fibonacci terms
2+
f0 = 0 # fibonacci number (1st term)
3+
f1 = 1 # fibonacci number (2nd term)
4+
while n > 0:
5+
print(f0) # print the current term
6+
nth = f0 + f1 # the nth term
7+
f0 = f1 # update first
8+
f1 = nth # update second
9+
n -= 1; # decrement number of terms left
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
fibonacci:
2+
addi a0, zero, 10 # number of terms we want
3+
addi a1, zero, 0 # fibonacci number (1st term)
4+
addi a2, zero, 1 # fibonacci number (2nd term)
5+
# now, a1 holds fibonacci_0 and
6+
# a2 holds fibonacci_1
7+
# Now calculate the rest of the terms, which will
8+
# go into a1 and a2 as the algorithm continues
9+
# After 10 iterations, a1 should hold 55 and a2 should hold 89
10+
fib_loop:
11+
add a3, a1, a2 # nth term
12+
addi a1, a2, 0 # update first
13+
addi a2, a3, 0 # update second
14+
addi a0, a0, -1 # decrement number of terms left
15+
bgt a0, zero, fib_loop # branch if not finished
16+

lectures/Assembly/slides.pdf

-94 KB
Binary file not shown.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
li a0, 67 # 0x43 or 0b01000111
2+
li a1, 0
3+
loop:
4+
andi a2, a0, 1
5+
add a1, a1, a2
6+
srli a0, a0, 1
7+
bne a0, x0, loop

0 commit comments

Comments
 (0)