MIPS Hangman Project - Get Random Word in MIPS

  • Thread starter Thread starter unoathingshad
  • Start date Start date
  • Tags Tags
    Mips Project
AI Thread Summary
The discussion focuses on creating a Hangman program in MIPS, specifically on how to select a random word from a file. The group plans to divide the program into three subroutines: one for file handling, one for random word selection, and another for game logic. A key challenge is determining how to read the words into memory and then randomly select one, with suggestions made about using predetermined string lengths and memory allocation. The importance of understanding data retrieval methods and how to pass addresses between subroutines is emphasized. Overall, the conversation highlights the complexities of implementing random word selection in MIPS programming.
unoathingshad
Messages
4
Reaction score
0
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 can't 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 :)?
 
Physics news on Phys.org
Are you asking how to generate random numbers in MIPS? Are your human words going to be stored in the MIPS data segment?
 
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.
 
Do you know how you're going to read the file?
 
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.
 
unoathingshad said:
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.

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.
 
Back
Top