You are here: Home / Past Courses / Spring 2019 - ECPE 170 / Labs / Lab 12: MIPS Assembly Programming (Advanced)

Lab 12: MIPS Assembly Programming (Advanced)

Overview

In this lab, you are going to write a program (in both C and MIPS assembly) that allows a human to play of game of Hangman.

Lab

In this game, the player is attempting to guess a hidden word, one letter at a time.  The hidden word can be hardwired in the program. For each correct letter guessed, the letter is revealed at its correct location or locations in the word.  For each incorrect letter guessed, an additional segment of the stick figure "hangman" is displayed.  The stick figure has 6 segments in total: head, body, left and right arms, and left and right legs.  The game is won when the entire word is guessed.  The game is lost when the entire hangman is displayed.  The game is exited upon winning, losing, or the user entering the 0 (zero) character.

You should not allow the player to make an illegal move, or to enter invalid input. For example, a player can't guess the same letter twice, or enter a number, or enter a non-printable character.  

Two examples of output are shown here (an all-incorrect example and an all-correct example). Your output does not have to match this exactly, but you do need to show the incremental stick figure, the current state of the guessed word, and any incorrect letters guessed.

Example output with incorrect guesses:

$ ./game 
Welcome to Hangman!
Version 1.0
Implemented by Jeff Shafer

 
   |-----|   Word: _______
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: Q
 
   |-----|   Word: _______
   |     |
   O     |   Misses: Q
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: W
 
   |-----|   Word: _______
   |     |
   O     |   Misses: QW
   |     |
   |     |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: E
 
   |-----|   Word: _______
   |     |
   O     |   Misses: QWE
  \|     |
   |     |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: R
 
   |-----|   Word: _______
   |     |
   O     |   Misses: QWER
  \|/    |
   |     |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: T
 
   |-----|   Word: _______
   |     |
   O     |   Misses: QWERT
  \|/    |
   |     |
  /      |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: Y
 
   |-----|   Word: _______
   |     |
   O     |   Misses: QWERTY
  \|/    |
   |     |
  / \    |
         |
 ---------
You lose - out of moves

Example output with correct guesses:

$ ./game 
Welcome to Hangman!
Version 1.0
Implemented by Jeff Shafer

 
   |-----|   Word: _______
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: H
 
   |-----|   Word: H______
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: A
 
   |-----|   Word: HA___A_
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: N
 
   |-----|   Word: HAN__AN
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: G
 
   |-----|   Word: HANG_AN
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Enter next character (A-Z), or 0 (zero) to exit: M
 
   |-----|   Word: HANGMAN
   |     |
         |   Misses: 
         |
         |
         |
         |
 ---------
Congratulations - you win!

Part 1: Implement the Hangman game in C
(1) You cannot use library functions other than printf(), scanf(), putc() and getc() , because there is no "C Standard Library" in the MIPS simulator or assembly language.
(2) You must provide a Makefile.
(3) Your game must use at least 3 subroutines -- feel free to use more. At least one of the subroutines must have parameters and at least one must return a value.  For example, you could use:
bool check_game(char *word)print_game()char user_input().
(4) You must fully check for valid inputs. 
(5) Use of global variables is acceptable because it may simplify your assembly programming.
(6) For grading purposes, your hidden word should be "HANGMAN".

You should completely test and debug your C implementation before moving on to Part 2. Assembly programming is slow and tedious. You DO NOT want to have to fix bugs later that were caused by a sloppy C implementation!

 

Part 2: Implement the Hangman in MIPS assembly
(1) **Each line** of assembly code must be documented with a comment!
(2) Each region of assembly code must clearly have a **comment block** documenting the overall purpose of that region, along with what values each register holds. You can use your own judgement for a reasonable region size.
(3) Implement the same subroutines as in your C program. They must take the same parameters and return the same values.
(4) You can assume that all user inputs have the proper format (i.e a valid character), but you still must check against the list of already entered characters and the game word. 

 

Lab Submission:
(1) There is no lab report for this lab.
(2) All source code must be submitted via Mercurial. Place the source files inside the lab12 folder that was previously created.

 

Optional Feedback: 
(Feel free to include a text file with comments/feedback on the lab)
(1) How would you suggest improving this lab in future semesters?

 

Resources

The MIPS Instruction Set and MIPS Example Programs will be very useful in this project.  Don't forget about the H&P Appendix A PDF in Canvas!  (It shows the full list of branch instructions)