MIPS Hangman Project - Get Random Word in MIPS

In summary, the conversation discusses how to implement a hangman program in MIPS, specifically how to generate random words from a text file. The group has divided the program into three subroutines, but is unsure of how to generate random numbers in MIPS. They also discuss how to read and store the words in memory, and how to convey this information between the subroutines.
  • #1
unoathingshad
4
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
  • #2
Are you asking how to generate random numbers in MIPS? Are your human words going to be stored in the MIPS data segment?
 
  • #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.
 
  • #4
Do you know how you're going to read the file?
 
  • #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.
 
  • #6
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.
 

1. What is the MIPS Hangman Project?

The MIPS Hangman Project is a programming project that involves creating a game of Hangman using the MIPS assembly language. The goal of the project is to familiarize students with programming in MIPS and to practice concepts such as loops, arrays, and file input/output.

2. How do you get a random word in MIPS?

To get a random word in MIPS, you can use the system call syscall 42 which generates a random integer. You can then use this integer to index an array of words and retrieve a random word.

3. What is the purpose of the MIPS Hangman Project?

The purpose of the MIPS Hangman Project is to help students understand and practice programming concepts in MIPS assembly language. It also allows students to apply these concepts in a fun and interactive project.

4. What are the key components of the MIPS Hangman Project?

The key components of the MIPS Hangman Project include creating a word bank, generating a random word, displaying the hangman game, taking user input, and checking for correct/incorrect guesses. Students will also need to use loops, arrays, and file input/output in their code.

5. How can I test my MIPS Hangman Project?

You can test your MIPS Hangman Project by running it in a MIPS simulator, such as MARS or QtSpim. You can also manually check for correct functionality by playing the game and making sure it correctly displays the hangman game and responds to user input. Grading rubrics or test cases may also be provided by your instructor.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
4
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
7
Views
2K
  • Programming and Computer Science
Replies
21
Views
551
  • Engineering and Comp Sci Homework Help
Replies
2
Views
14K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
23K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
4
Views
12K
Back
Top