 For this example, I'm going to work through writing a factorial function. I will start by writing some driver code to get input from the user and print our output back to the user when we're done. Then I will go back through and fill in the actual algorithm that we'll use to calculate the results of our factorial. So I will start with all of these strings that I'm going to be using. And now I will start querying the user for the information that I need. So when I get a response from my user, it will come in in v0, and I will copy that over to t0. I think that I will store my results in t1. So when I'm done, I will copy whatever is in t1 into a0. So those four blocks will print out my original integer, my exclamation point and equal sign, and then the results of my computation. And finally we will quit the program. So in between here, I also need to add all of my code to actually calculate my factorial. In a high level language, my factorial code would look something like this, and then x would hold the results of my computation. So I want to do something similar here, so I'm going to be interested in building a for loop. My for loop begins by initializing both a counter, i, and a variable to hold my result, which I labeled x. So I need to define those two. I will use t2 for my counter, and I already said that I would use t1 for my result, so I will use t1 as my result variable. Once I've got my initialization, then I would do my test next. I am interested in running this loop until i is not less than or equal to n. So n is in t0. Once my counter is greater than n, then I'm going to want to exit, and the test will form the beginning of my loop here. Inside the loop, I need to do two things. I'm going to increment my counter, and I'm also going to multiply my result by my counter. So I'm going to begin by multiplying the result by my counter, and next I will increment my counter. Once I'm at the end of my loop, then I just need to go back to the beginning and start the whole process over again. And finally, I'll add a label to indicate that this is outside of my loop, and this is where we're going to go once we're done running this code. So this should be all I need for a factorial function. So I'm going to take this code and come over and run that in QTSPim. And QTSPim is telling me that I forgot my main label. So I will go back to the very beginning of my code and add a main label. Now QTSPim will know where to start. Open my console and put in 5. I get that 5 factorial is 120, just like I would expect. If I run this again, 6 factorial is 720, which is also what I expect to see. So this is an example of how I could write factorial. I've used one for loop that does the same thing as a for loop that I would write in a high-level language, but it's doing it in assembly language instead.