title: MIPS: n choose k function
body: <p>So I'm currently writing a calculator in MIPS and I'm trying to write an n choose k function. 
  The algorithm I want to use is this: </p>
  
  <p>If I want to do 5 choose 3 then I'll have a loop that does (5*4*3)/(3*2*1). Suppose I already have multiply and divide functions, how would I implement this in MIPS?</p>
  
  <p>Right now I have this, but it isn't working at all:</p>
  
  <pre><code>calnchoosek:
      move $t1, $a0
      move $t2, $a2
  
      move $t3, $a0 # copies for the counter
      move $t4, $a2
  
  loop_top:
      beq $t3, $t4, loop_bottom
      subi $t3, $t3, 1
  
      move $a0, $t1
      move $a2, $t3
      jal multi
      move $t1, $v0
  
      j loop_top
  
  loop_bottom:
      beq $t4, $zero, exit1
      subi $t4, $t4, 1
  
      move $a0, $t2
      move $a2, $t4
      jal multi
      move $t2, $v0
  
      j loop_bottom
  
  exit1:
      move $a0, $t1
      move $a2, $t2
      jal divi
  </code></pre>
  
  <p>I'm thinking my logic is totally flawed and I might have to start fresh. Could anyone help me?</p>