Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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;i n-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.)
Can someone help me edit my code so it can run and get the answer? When I ran the code I got the answer of 1203628800. I need the answers
from 1b, please and I also need help with EndLoop1 from my code below.
result: word 0
.text
Invert to and an for decrementing. You want to decrement a temporary register, not ae.
main:
Call coubinations with a=10,r=5
li $a,10inn
li,$a,5inr
jal conbinations
combinations
Store result in menory
# Display result for n=10,r=5
ii $ve,1
Call combinations with n=180,r=10
11,$06,100
11,$01,10
li $a1,10
combinations
$va, result is store result in menory.
Display result for n=160,r=10
Fisplay result Li $ve,1
lus $ab, result & Load the result from aenory
exit:
Lisyscall $ve,10, exit with syscall 10
conbinations:
i. Prologue.
addi $5p,$5p,-8, Allocate space for local variables
su $sa,4($sp)
$sa,4($sp) $ab,e($sp)
$a1,4($sp)
Save return address
Save n
li $te,1, Initialize c=1
Loop to calculate (n-r+1)**(n-r+2)**dots**n
add $t1,$a,$
87
88 Loop:
89
90
91
92
mul $v0,$v0,$t1
addi $t1,$t1,1
bne $t0,$t1, loop
jr
$ ra
# v0**=t1
# t1+=t1
# and return
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database And Expert Systems Applications 19th International Conference Dexa 2008 Turin Italy September 2008 Proceedings Lncs 5181

Authors: Sourav S. Bhowmick ,Josef Kung ,Roland Wagner

2008th Edition

3540856536, 978-3540856535

More Books

Students also viewed these Databases questions

Question

What are barriers to communication?

Answered: 1 week ago

Question

Write a program to check an input year is leap or not.

Answered: 1 week ago

Question

Write short notes on departmentation.

Answered: 1 week ago

Question

What are the factors affecting organisation structure?

Answered: 1 week ago

Question

What are the features of Management?

Answered: 1 week ago

Question

Briefly explain the advantages of 'Management by Objectives'

Answered: 1 week ago