Lab 04
Simple Loops
Implement a function i32 @sum(i32 %n) that sums up all integers from 0 to %n using a loop.
For this first task, it is fine to write your code in C and then generate the LLVM assembly:
clang -S -emit-llvm loop.c to generate loop.ll.
For all of the following tasks, try and write them from scratch.
Fibonacci Numbers
Implement a function i32 @fib(i32 %n) that returns the nth Fibonacci function using recursive function calls, but no loops.
Can you optimize this function?
Greatest Common Denominator
Implement a function i32 @gcd(i32 %x, i32 %y) that uses the Euclidean algorithm.