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 need help editing my code because my outputs are supposed to be 252 and 17,310,309,456,440 but for some reason everytime I
change my code it keeps giving me different answers. This time when I run it, my output is 60480. Please help me get 252 and
17,310,309,456,440!!
data
result: ,word 0
.text
-globl main
Invert to and a0 for decrementing. You want to decrement a temporary register, not a0.
main:
# Call combinations with n=10,r=5
jal
combinat
$ve, result #Store result in memory
# Display result for n=10,r=5.
li $ ve,1
lw $a0, result # Load the result from memory
# Call combinations with n=100,r=10
li $00,100,#n
li $01,10,#r
jis $a1,10 #r
jal
combinations
$ve, result #Store result in memory
# Display result for n=100,r=10
li $ ve,1
syscall $ ab, result #Load the result from menory
exit:
limsyscall$ve,10, # exit with syscall 10
combinations:
# Save registers
addi $5p, $sp,-4
su $ra,0($sp)
Save n and r
nove $t2,$a,#$t2=n
nove $t1, $a1
#$t2=n #t1=r
 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!