1. Limited time only! Sign up for a free 30min personal tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Homework Help: Mips hangman project

  1. Apr 12, 2012 #1
    Ok so me and a my group are writing a hangman program in mips, we came up with the idea of dividing the program to 3 subroutines 1 that reads and writes to a file, one that picks a random word from a word bank in the text file i guess, and one that does the rest like getting the word replacing it with -,-,- while the user is guessing and so on.

    i have done this program before in java but its much easier it seems, i picked the subroutine that gets a random word but i cant think of a way to get it in mips.

    What i thought of doing was loading a random word from memory that the first subroutine was suppose to have loaded, then get a random address of where the word is stored using something like
    li $v0, 42
    but i still very uncertain on how to go about this, any advice please and tank you :)?
  2. jcsd
  3. Apr 12, 2012 #2
    Are you asking how to generate random numbers in MIPS? Are your human words going to be stored in the MIPS data segment?
  4. Apr 12, 2012 #3
    i know i how to generate random numbers using li v0 42, and the words are suppose to be stored in a text document, but with the first subroutine mips suppose to read them, my problem is how to pick a random one.
  5. Apr 13, 2012 #4
    Do you know how you're going to read the file?
  6. Apr 15, 2012 #5
    well me and my friend split the program, he is in charge of that part. is it necessary to know how the will be read?, we talked about reading them and saving them in memory but am still unsure how it is going to happen.
  7. Apr 15, 2012 #6
    It's important to know how you will be receiving the data. How else can you randomly select from it? Will he store it on the stack, or will he do a call to the heap to allocate memory? And how will you know how long each string is? Will you agree on a predetermined size of strings, so you don't have to keep up with it per string (are you willing to waste space?)? For example, just choose string length to be the longest one there is, and pad all the others with null bytes?

    If we assume that, then all you really need is for him to pass
    a0 the address of the first byte in the character array of human words
    a1 the length of the largest string (i.e. the length of all strings then)
    a2 the number of strings total

    You will then generate a random number based on a2 then transform it based on a0 and a1 to generate the address of a string randomly.

    You now have to decide how to convey the information to him. What are your return arguments? Do you pull it out of memory? If so, where do you put it? This may not be the best idea, because you will most likely pull it out of memory just to put it back somewhere else in memory and then have him pull it out of memory. Maybe you could just pass him the address to the string in question. HE then knows a1 (he passed it to you after all) and can pull it out of memory himself using several lb commands, the address you returned, and his knowledge of a1.
Share this great discussion with others via Reddit, Google+, Twitter, or Facebook