MIPS: n choose k function -


so i'm writing calculator in mips , i'm trying write n choose k function. algorithm want use this:

if want 5 choose 3 i'll have loop (5*4*3)/(3*2*1). suppose have multiply , divide functions, how implement in mips?

right have this, isn't working @ all:

calnchoosek:     move $t1, $a0     move $t2, $a2      move $t3, $a0 # copies 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 

i'm thinking logic totally flawed , might have start fresh. me?

in loop_bottom, $t4 set 0 in last iteration. multiply $t2 0 , 0 denominator. divi calculating k*(n!-k!)/0 – divided zero!


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -