Question: 1 a . Write a function combination which implements the combinatorial function n C r in MIPS assembler. A straightforward Java implementation without checks is

1a. Write a function combination which implements the combinatorial function nCr in MIPS assembler.
A straightforward Java implementation without checks is given here:
int combinations(int n, int r){
int c=1;
for(int i=r+1;in;i++
c**=i;
for(int i=1;in-r;i++
c?=i;
return c;
}
1b. The assemble instructions for multiplication and division, respectively, are mul and div.
Use the non-recursive factorial example with loops from the class as a starting point.
Write a main function which calls combinations twice with hardcoded n and r as follows:
a.n=10,r=5(The answer is 252.)
b.n=100,r=10(The answer is 17,310,309,456,440 which takes more than 32 bits to represent!)
Exit your program with the proper syscall.
1c. Test and run your program. Provide a screenshot of test runs for the two cases.
(I haven't learned mflo or mfhi.)
.text
main:
??#Call combinations with n=10,r=5
li $a0,10
li $a1,5
jal combinations
# Display result for n=10,r=5
??# Display result
lw ste, svil
li $ve,1
move $ve,1
sae, ste
syscall
ji jal combinations
# Display result for n=100,r=10
iw ste, sv1 li sve, 1
move $su0,1 mto
syscall
exit: lisyscall $v,10," exit with syscall 10
# subroutine FACTORIAL(n)
# calculates n**(n-1)**(n-2)**dots**1 IN: $a=n
# OUT:
$a=n $v0= FACTORIAL (n)
$te,$t1,$ve
combinations:
#Function proglogue
sw swa, o( $sp
$sa,0($sp) $s0,4($sp)
$s1,8($sp)
# Initialize result to 1
list0,1
sw $t0, $v1
Error line 10 column 9: "lw": Too few or incorrectly formatted operands. Expected: lw $t1,-100($t2)
Error line 21 column 9: "lw": Too few or incorrectly formatted operands. Expected: lw $t1,-100($t2)
Error line 42 column 9: "sw": Too few or incorrectly formatted operands. Expected: sw $t1,-100($t2)
Error line 52 column 11: "lw": Too few or incorrectly formatted operands. Expected: lw $t1,-100($t2)
Error line 54 column 11: "sw": Too few or incorrectly formatted operands. Expected: sw $t1,-100($t2)
Error line 64 column 11: "lw": Too few or incorrectly formatted operands. Expected: lw $t1,-100($t2)
Error line 66 column 11: "sw": Too few or incorrectly formatted operands. Expected: sw $t1,-100($t2)
Assemble: operation completed with errors.
 1a. Write a function combination which implements the combinatorial function nCr

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!