Do you have any information about the simplifying algebra that is mentioned? I can most likely write the MIPS code but I haven't dealt with the "n choose k" algebra in a while. I know the formula is n! / (k! (n-k)!), but can't quite remember the simplifying tricks.
Also, could you upload the original document you pasted above?
Sometimes pasting formatted data directly into this site doesn't render as you'd expect, and can become difficult to read.I'm not sure I got all the information correctly and completely.
OK, I think I found an approach. If I'm right it won't even need to use the supplied factorial routine.. could that be?
Anyway, I will have to tackle this in the morning. Few more things
- it talks about "Use the System Calls on page A-44..."
any way you could let me see what is says there? Take picture and post it here?
- What MIPS programming/simulation tools do you use? Is it QTSpim (http://spimsimulator.sourceforge.net/) or something else?
I also use MARS at times, which is a little different... that vast majority of the assembly code will be the same either way, but please let me know which one you use, so I can make sure my solution works for you.
Well, I went ahead and wrote it in QtSpim for you:
As you can see the NCK subroutine is really simple, doesn't have to calculate any factorials expliticly.
I found the clue at https://en.wikipedia.org/wiki/Combination
Please let me know if you need anything else.