How JustAnswer Works:

  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.

Ask Ingo U Your Own Question

Ingo U
Ingo U, Software Engineer
Category: Homework
Satisfied Customers: 755
Experience:  Over 25 years experience in software development. Expert in Microsoft .Net, C#, C++, VB, SQL
44076068
Type Your Homework Question Here...
Ingo U is online now
A new question is answered every 9 seconds

The subroutine example on the following page, calculates the

Customer Question

The subroutine example on the following page, calculates the Factorial of an input integer. Starting with the code in the example, write a correct program in MIPS - SPIM assembly language that: 1) Calculates the odds of winning the Power Ball grand prize jackpot. 2) The calculated value is to be displayed on the SPIM screen with the appropriate commentary text. Such as “the odds are 1 in nnnn.” 3) Test your program by calculating the odds of choosing a set of 3 numbers from a set of 7 numbers. 4) The program is to accept as input:  An integer representing the large pool of possible numbers.  A second integer representing the count of numbers to be selected from the large pool. Note: Because the largest MIPS single precision integer value will not hold the value of more than 12!, you will need to use some algebra to simplify the calculations. With the simplifications, all the math can be done using the integer multiply. Additionally, it is expected that your program will handle correctly only a small subset of all the possible probability / odds calculations. You can use the fact that the number of balls selected will be less than 12, and that you can use the provided factorial subroutine. Use the System Calls on page A-44 for the input and output. The work products of this assignment are: 1) A copy of the source program. 2) Screen captures showing the output results. [ 150 points ]
pfctrl:
sw $ra, 4($sp) # ***** the return address
sw $a0, 0($sp) # ***** the current value of n
addi $sp, $sp, -8 # ***** stack pointer
slti $t0, $a0, 2 # ***** 1 iteration, n=0 or =1;n!=1
beq $t0, $zero, L1 # ***** calculate n(n-1)!
addi $v0, $zero, 1 # *****=1; n!=1
jr $ra # ***** multiply
L1:
addi $a0, $a0, -1 # ***** := n-1
jal pfctrl # ***** (n-1)!
addi $sp, $sp, 8 # ***** the stack pointer
lw $a0, 0($sp) # ***** saved (n-1)
lw $ra, 4($sp) # ***** return address
mul $v0, $a0, $v0 # ***** (n)*(n-1)
jr $ra # ***** value n!
Submitted: 11 months ago.
Category: Homework
Expert:  Ingo U replied 11 months ago.

Do you have any information about the simplifying algebra that is mentioned? I can most likely write the MIPS code but I haven't dealt with the "n choose k" algebra in a while. I know the formula is n! / (k! (n-k)!), but can't quite remember the simplifying tricks.

Also, could you upload the original document you pasted above?

Sometimes pasting formatted data directly into this site doesn't
render as you'd expect, and can become difficult to read.
I'm not sure I got all the information correctly and completely.

Thanks,

Ingo U

Customer: replied 11 months ago.
I'm not sure but below I have pasted some discussion threads from other people doing the project :___________________________________________________________________________________________________Many of your questions can be answered by going to the PowerBall website: http://www.powerball.com/Additionally, your program needs to be general enough to calculate the 'odds' of other choose K from N problems.This exercise expects that you will do some independent research as part of your solution.
___________________________________________________________________________________________________The mathematics behind the PowerBall and other lotteries is the possibilities of choosing a set of K objects from a set of N objects. The solutions require calculating factorial values. N choose K is a well known problem in combinational math.This programming assignment is for you to write a program, using factorial calculations, that calculates the number of sets given N objects, choosing K of them. The Powerball ‘odds’ is a specific case. Your program is to be general enough that it will correctly calculate when given input values in the range of N less equal 60, and K less equal 11.Your testing should include small numbers so that you can prove to yourself that your program solution is correct. 6 choose 2 equals 15; for example and then 7 choose 3 equals 35.You can 'hardcode' the red ball value = 35.
___________________________________________________________________________________________________
The program that you are to write is to use the "old" Powerball game. The problem was written Before the Powerball game was changed in October.Sorry about that.There are just two input values. N the value of the large pool of numbers, and K the count of numbers to be chosen.See also the other discussion thread.
Expert:  Ingo U replied 11 months ago.

OK, I think I found an approach. If I'm right it won't even need to use the supplied factorial routine.. could that be?

Anyway, I will have to tackle this in the morning. Few more things

- it talks about "Use the System Calls on page A-44..."

any way you could let me see what is says there? Take picture and post it here?

- What MIPS programming/simulation tools do you use? Is it QTSpim (http://spimsimulator.sourceforge.net/) or something else?

Expert:  Ingo U replied 11 months ago.

I also use MARS at times, which is a little different... that vast majority of the assembly code will be the same either way, but please let me know which one you use, so I can make sure my solution works for you.

Expert:  Ingo U replied 11 months ago.

Well, I went ahead and wrote it in QtSpim for you:

https://www.dropbox.com/s/96lrcxdd4kn16tb/nck.asm?dl=0

As you can see the NCK subroutine is really simple, doesn't have to calculate any factorials expliticly.

I found the clue at https://en.wikipedia.org/wiki/Combination

Please let me know if you need anything else.

Ingo

Expert:  Ingo U replied 11 months ago.
THIS ANSWER IS LOCKED!
You can view this answer by clicking here to Register or Login and paying $3.
If you've already paid for this answer, simply Login.