 This time I'm going to be writing a function to calculate the prime factorization of a number. I've got some pseudocode explaining the algorithm that I'm going to write, but first I'm just going to start by writing down all of the driver code. This code will request a number to fact from the user and then print out the results in the end. So I will start with my query and then I'll have a generic response. And since I want to be able to put commas and spaces between my numbers, I'm adding in a line for that. And at the very end I want to have a period and an end line. So first I'll request a number from the user and copy that number to t0. Then I would go through the process of factoring the number and then finally display the results. But unlike the previous example, I'm actually going to be printing out my results as I go. My algorithm prints out a new factor every time it finds one. So I will start with a bunch of output print code and we'll actually have our algorithm set up to print the results as it's running. So now I want to implement all of my pseudocode that I've got for the algorithm. So this time I have a while loop that I'm working with and it's looking for some value. It's less than n and this i is going to be my counter. So I will start by defining a counter and should be initialized to 2 because that's the smallest prime factor that I can have. So for my while loop, I'm going to make sure that I remain in this while loop as long as my counter is less than the provided number. So once my counter is greater than or equal to my provided number, then I want to want to end my loop. So now I have some space for my loop. Inside my loop is just an if statement. I have an if and an else case and the test is based on n modulo i. So I'm going to do some division. I'll divide my n by my i and I'm going to look at the remainder. I can actually use the REM pseudo instruction and divide n which is in t0 by i which is in t1 and if the results of that are not equal to 0, then I'll go to my else case. In the true case though, I want to print out an i and then divide my n by i. So i is in t1 so I will copy that to a0 so I can print that out. So then I want to be able to print the comma. Next I need to divide n by i. I can actually simplify this code a bit and use an actual division instruction instead of the remainder pseudo instruction. But now I have to get my remainder and put that in $2 t2 so that I can use that in my branch not equal to 0 instruction. So I will get that data from the high register and now that means that the results of the actual division are in the low register. So I can actually just use those directly and I want to store those into my n which is $t0. This forms the end of my block here. I don't want to do anything more for my if statement. I'd like to jump over the else case if I went into the true case. So in a normal case I would just go down to the end of my block, go to after the else statement. But in this case I know that after I get done with my if statement I'm just going to go back through the while statement. So I can actually just jump back to my while label to begin with. Now I can go right the else block and the else block says well just increment i. And then we'd fall out of the if block and go back to our while loop. Once we exit the while loop there isn't much left of our pseudocode. We just want to print off the last factor and close up our program. So I will print out the last factor, print out a period and an end line and then end my program gracefully. If I come over to QTSpim and run this program it again tells me that I forgot my main label. So I will go back up and add a main label at the beginning of my program. If I look at the console it asks me for a number to factor. Give it 10, it tells me the factors of 10 are 2 and 5. Give it a larger number, factors of 42 are 2, 3 and 7. So there is our prime factorization algorithm. All we had to do was implement one while loop that had an if else block. Thank you.