 For this example, we're going to look at a recursive Fibonacci function. Again, I have my code on the left-hand side and my registers and memory on the right-hand side. My code begins on line 61 with the main function where it says, Take 4 and put it into A0 so that we can calculate the fourth Fibonacci number. Next, line 62 says jump in link to Fibonacci. So I go down to my return address and enter the next instruction, which is line 64. And then I'll go to my Fibonacci function, which starts on line 29. Line 29 says put 1 into T0. Then, if A0 is greater than T0, go to Recurse. 4 is greater than 1, so I will go down to line 41. Line 41 says allocate 12 bytes on my stack. So I will move my stack pointer down 12 bytes, which will make room for three integers. Then it says I should take my return address and store that at stack pointer plus 8. So my return address is line 64, and that goes in the first position. Next, it says to store my parameter at stack pointer plus 4. So I've put the 4 up there. Then line 45 says take A0 and subtract 1. And then I have a jump in link to Fibonacci. So I'm going to write down the address of my next instruction, which is line 47. And then I'm going to go back to line 29. Line 29 says put 1 into T0. Then if A0 is greater than T0, go to Recurse. So 3 is greater than 1, so I will go down to line 41. This tells me to allocate 12 more bytes on my stack. So I moved my stack pointer down 12 bytes. Then I'm going to store my return address at stack pointer plus 8. And then my parameter at stack pointer plus 4. Next, I subtract 1 from A0, store that back in A0. Then the jump in link to Fibonacci says put the address of the next instruction to the return address. So that's line 47. And then go to line 29. Line 29 tells me to put 1 into T0. Then if A0 is greater than T0, I should go to Recurse. 2 is greater than 1, so I will go down to line 41. Line 41 says allocate 12 bytes of space on my stack. Then store my return address at stack pointer plus 8. So I copy the line 47 there. Next, I store A0 at stack pointer plus 4. So 2 goes in there. Then subtract 1 from A0 and store that back in A0. Now I have a jump in link to Fibonacci, so I write down the address of the next instruction in my return address, which is line 47. Then I go back to line 29. Line 29 says put a 1 into T0. Then if A0 is greater than T0, go to Recurse. 1 is not greater than 0. So I'll run line 32, which says if A0 is not equal to 0, then I should go to 1. 1 is not equal to 0, so I go down to line 36. This tells me to put a 1 into V0 and then go to my return address. So I'll go down to line 47, which says take the contents of V0 and store it at stack pointer plus 0. So I will put a 1 at stack pointer plus 0. Next I go to stack pointer plus 4, read that data, and store it at A0. So that's loading this 2 and storing it into A0. I then subtract 2 from A0, leaving me with 0, and then I have a jump in link to Fibonacci again. I will write down the address of my next instruction as my return address, which is line 53. And then I will go back to line 29. Line 29 tells me to put a 1 in T0. Then if A0 is greater than T0, I will go to Recurse. 0 is not greater than 1, so I go to line 32, which says if A0 is not equal to 0, then go to 1. 0 is equal to 0, so I go down to line 33, which says put 0 in V0. Next line 34 says go back to my return address, so I will go down to line 53. Line 53 says read the data from stack pointer plus 0 and store it at T0. So stack pointer plus 0 has a 1, so I will store that into T0. Next I add T0 to V0 and store that in V0. 0 plus 1 is 1, so I will put a 1 in V0. Next I read return address from stack pointer plus 8. That says line 47, so there's my new return address. Next I need to deallocate the 12 bytes of storage, so my stack pointer now points there. And then I go back to the return address, which is line 47. So line 47 says take what's in V0 and put it at stack pointer plus 0. So I put a 1 in there. Then I go to stack pointer plus 4, read that data and store it into A0. So stack pointer plus 4 has the value 3, so I will put that in A0. Next I subtract 2 from A0 and store that back in A0. And then go to my Fibonacci function again. So I will store the address of my next instruction, which is line 53. And then go to line 29. Line 29 says put 1 into T0. Then if A0 is greater than T0, I'll go to recurse. So 1 is equal to 1, so I'll go down to line 32, which will tell me to go to line 36, where I would put a 1 in V0. And then go to my return address, which is line 53. Line 53 says load stack pointer plus 0, which is the value 1, and store that into T0. Line 54 says add T0 to V0 and store that in V0. 1 plus 1 gives me 2, so that's my new value for V0. Line 56 says read the value from stack pointer plus 8 and store that as my return address. So that's referencing line 47. So that will be my new return address. Next I need to deallocate the 12 bytes of storage that I used for this function. So my stack pointer now points up there. Then I'll go to my return address, which is line 47. Line 47 says take whatever's in V0 and store that at stack pointer plus 0. So I put a 2 up there. Line 49 says read what's at stack pointer plus 4 and store it into A0. Stack pointer plus 4 is that 4, so that will go into A0. Next I subtract 2 from A0, store that back in A0, and then I'll go to my Fibonacci function again. So I will write down the address of my next instruction, and then go to line 29, where I will store a 1 in T0. Notice that 2 is greater than 1, so I will go to recurse, which means I'll need to allocate 12 bytes of memory on my stack. So there's my stack pointer now. Now it tells me to take my return address and store it at stack pointer plus 8. So I set stack pointer plus 8 to reference line 53. Then it says take A0 and store that at stack pointer plus 4. So A0 is 2, so it goes in that spot. Next line 45 says take A0 and subtract 1. Then jump in link to Fibonacci. So I will set my return address to be line 47, and then I'll go to line 29. Line 29 says put 1 in T0. Then if A0 is greater than T0, go to recurse. It's not, they're equal, so I'll end up down at line 36, where I put a 1 in V0. Then I'll go to my return address, which is line 47. Line 47 says take what's in V0 and store it at stack pointer plus 0. So I will stick a 1 in that spot. Line 49 says read the data from stack pointer plus 4 and store it in A0. So I will take this 2 and put it into A0. Then I'll subtract 2 from A0, leaving me with 0. Then I'll call my Fibonacci function again. So my return address is line 53, and I'm back at line 29 again. Put 1 in T0. 0 is less than 1, it's equal to 0. So line 33 says put 0 into T0. Then go to my return address, which is line 53. So I will load stack pointer plus 0 into T0. Then add T0 to V0 and store that in V0. Line 56 says get my return address back from stack pointer plus 8. So that's this line 53. And then deallocate 12 bytes of storage from the stack. Finally, I go back to my return address, which was line 53, which says go to stack pointer plus 0, load that data and store it into T0. So I put a 2 in T0. Then I add T0 to V0, store that in V0. 2 plus 1 gives me 3. And then I'm going to load my return address from stack pointer plus 8. I'll be pointing at line 64. Then I deallocate 12 bytes of storage and go back to my return address. So line 64. I'm now outside of my Fibonacci function. It tells me to copy V0 to A0, put a 1 in V0, and then print out A0. The result of Fibonacci 4, the number 3, would show up. Then I'd put a 10 in V0, and then another syscall would make the program quit.