recursion - Conversion of recursive C function into ARM assembly? -
for homework assignment, i've been given recursive c function count integer partitions need convert arm assembly. things know arm assembly:
1) r0
hold return value of call
2) r1
, r2
, , r3
argument registers
the code follows:
int count_partitions(int n, int m) { if (n == 0) return 1; else if(n < 0) return 0; else if (m == 0) return 0; else return count_partitions(n - m, m) + count_partitions(n, m - 1); }
i believe have done first 3 if & else-if
statements correctly. logic final else
statement find count_partitions(n, m-1), store onto stack, find count_partitions(n-m, m)
, , add previous return value got stack - code not seem work?
i've attached attempted solution , have color coded different segments of c code , corresponding assembly code. let me know what's wrong?
you can use after cmp command , jump function:
beq label ; branch equal
bne label ; branch not equal
ble label ; branch less equal
blt label ; branch less than
bge label ; branch greater equal
bgt label ; branch greater than
Comments
Post a Comment