Skip to content

RaidaHossain/mips-binary-game

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 

Repository files navigation

MIPS Binary Game

Overview

The MIPS Binary Game is an interactive game written in MIPS assembly that helps users practice converting between decimal and binary numbers. The game is structured into 10 levels, where each level contains a number of problems equal to the level number. This results in a total of 55 problems throughout the game.

For each problem, the game randomly selects one of two modes:

  • Binary to Decimal
  • Decimal to Binary

All problems are randomly generated at runtime. This project was developed as part of a Computer Architecture course and demonstrates low-level programming, modular design, and correct register usage in a MIPS environment.


Game Rules & Scoring

  • Each correct answer awards 10 points
  • Incorrect answers do not deduct points
  • The correct answer is displayed after an incorrect attempt
  • Maximum possible score: 550 points (55 × 10)

At the end of the game, the final score is displayed as: Final Score: X / 550

Project Structure

The program is organized into modular assembly files to improve readability and maintainability: src/

├── main.asm # Main game loop, level control, scoring

├── binary2decimal.asm # Binary → decimal conversion logic

├── decimal2binary.asm # Decimal → binary conversion logic

├── validation.asm # Input validation routines

├── syscalls.asm # Named syscall helpers for readability

Additional documentation: docs/

├── User_Manual.pdf

├── Project_Report.pdf


How the Program Works

main.asm

  • Displays the welcome message
  • Controls level progression
  • Randomly selects the problem mode
  • Calls the appropriate conversion module
  • Handles scoring and end-of-game output

binary2decimal.asm

  • Generates a random decimal number in the range 0–255
  • Converts the number to an 8-bit binary value
  • Displays the binary using ASCII-art boxes
  • Prompts the user for the decimal equivalent
  • Validates input and checks correctness

decimal2binary.asm

  • Generates a random decimal number in the range 0–255
  • Prompts the user to enter an 8-bit binary number
  • Validates that the input contains only 0 and 1
  • Converts the binary input to decimal and checks correctness

validation.asm

  • Validates decimal inputs (range 0–255)
  • Validates binary inputs (only 0s and 1s allowed)
  • Prompts the user to re-enter invalid inputs

Algorithms & Techniques Used

  • Modular program design in MIPS assembly
  • Loop and branch-based control flow
  • Proper register usage ($s registers for persistent state)
  • Random number generation using SysRandIntRange
  • ASCII graphics using +, -, and |
  • MIDI sound effects using syscall 31

Challenges & Solutions

  • Binary comparison logic:
    Binary input was stored as a string, converted to decimal character-by-character, and compared against the generated value.

  • Register usage bug:
    Level progression failed when stored in a $t register. Switching to a $s register fixed the issue.

  • Bit-length error:
    An off-by-one loop counter caused incorrect bit generation and was corrected.

  • Syscall assembly errors:
    Errors caused by MARS assembling helper files separately were fixed by disabling Assemble file upon opening and including syscalls.asm only in main.asm.


Extra Features

  • ASCII-based game board for displaying numbers
  • Level transition banners using =
  • MIDI sound effects for game start and end
  • Custom welcome and ending melodies

What I Learned

  • Designing modular programs in assembly language
  • Managing control flow and persistent state using registers
  • Validating user input at the assembly level
  • Debugging low-level syscall and assembly issues
  • Structuring non-trivial MIPS programs cleanly

Future Improvements

  • Add a timer for each question
  • Implement a graphical interface
  • Save and display high scores
  • Deduct points for incorrect answers

Notes

This project was originally developed for a Computer Architecture course and is shared for educational and portfolio purposes.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published