 For this example, I'm going to be writing an iterative Fibonacci function. I've got the header for my Fibonacci function up here. And I'm going to be using the test suite that we generated in a previous example. So to write my Fibonacci function, the first thing I need is the name of my function. In this case, the name is Fibonacci. So I'm just going to put that in as a label. I've got the word Fibonacci and then a colon following it to indicate that this is a label. And since the thing that follows it is going to be code, the assembler will know that this is a label for a line of code. So my function will expect to get its parameters in A0 through A3 because that's where parameters are always found. This time I only have one parameter, so it's in A0. It's going to be some unsigned integer index because negative numbers don't make any sense for Fibonacci. And when my function is done, my result will be some other integer for Fibonacci number. And my result will go in V0 because that's where results always go. To start my function, I know that Fibonacci of 0 is 0 and Fibonacci of 1 is 1. So if my parameter is either one of those, I can just return the result directly. I don't have to compute anything. So if my parameter is equal to 0, then I can just return 0. So way down here somewhere, I will put in a return 0 label, which just puts 0 into V0. And then I want to return to my calling function. The jump register $RA instruction will give me a way to do that. It's going to go to whatever instruction is pointed to by the value in the return address register. This is a register that's used solely for function call returns. And it is the counterpart of the jump and link instructions that we used earlier. The jump and link tells the computer to go to the Fibonacci label and also to set the return address to point to this instruction right after the jump and link. When I call this jump register instruction, it will send the computer back to running this move instruction next. Now that I've done Fibonacci of 0, I'm going to do Fibonacci of 1. So if my parameter is equal to 1, then I'll go to some label return 1. And same thing, I'll put 1 into V0 because that's where my results go. And then I will go back to the calling function by using the jump register to the return address. So now I know that I have something greater than 1 as my parameter, and I'm going to need to find that. I'm going to start by putting some values into a couple of registers to represent Fibonacci of n minus 1 and Fibonacci of n minus 2. So I'm putting 0 into T0 and 1 into T1. T0 will represent Fibonacci of n minus 2 and T1 will represent Fibonacci of n minus 1. Now I need to build a loop that will allow me to iterate over this number of times until I get to the correct value. So I will start at 2 because I know that my parameter is at least 2. And I'm going to repeat this loop until my counter is greater than my parameter. To calculate Fibonacci for the current counter, I'm going to add Fibonacci of n minus 1 to Fibonacci of n minus 2. And I'm storing that in T2. Now I need to shift all of my values down so that I'll be ready for the next iteration. Next I'll increment my counter and then I'm going to go back and run my Fibonacci loop again. Once this is done, I know that the last iteration through was calculated Fibonacci of n and it put those results into T2. So I'm going to copy those results from T2 into V0 and then I'm going to go back to the calling function. That should be all I need to do for my Fibonacci function. So I'm going to see if this works. I've loaded it with my test suite. Then if I open my console, it tells me that yes, all 10 of my tests passed. I checked everything from Fibonacci of 0 up to Fibonacci of 9 and they all came out correctly. So in this case I've built a function by having the name of a function. I can return from my function by using the jump register return address instruction. And other than that I need to follow a couple of conventions. I expect that all parameters are given in the argument registers and all of the results are given in the V registers. But those are the only things I really need to worry about for actually building a function. Everything else is the logic about how those results get computed.