Assembly Maze Game - MIPS Programming
A challenging maze game written entirely in MIPS assembly language. This project demonstrates low-level programming concepts, memory management, and game logic implementation at the assembly level. Navigate through the maze using keyboard controls and reach the goal to win!
Academic Background: My expertise in low-level programming was further developed through my capstone project - contributing to Ironclad, a partially formally verified real-time kernel written in SPARK and Ada. This project involved working with kernel-level programming, memory management, and system architecture design.
- Language: MIPS Assembly
- Platform: MARS (MIPS Assembler and Runtime Simulator)
- Features: Player movement, collision detection, maze generation, win condition
Interactive MIPS Assembly Demo
Interactive MIPS simulator - Try running the maze game code above!
Assembly Code Showcase
Player Movement Logic
# Player movement in MIPS Assembly
move_player:
# Load current player position
lw $t0, player_x
lw $t1, player_y
# Check input direction
lw $t2, input_direction
beq $t2, 1, move_up
beq $t2, 2, move_down
beq $t2, 3, move_left
beq $t2, 4, move_right
j end_movement
move_up:
addi $t1, $t1, -1
j check_collision
move_down:
addi $t1, $t1, 1
j check_collision
move_left:
addi $t0, $t0, -1
j check_collision
move_right:
addi $t0, $t0, 1
j check_collision
Collision Detection
# Collision detection system
check_collision:
# Calculate array index for new position
mul $t3, $t1, maze_width
add $t3, $t3, $t0
# Load maze array base address
la $t4, maze_array
add $t4, $t4, $t3
# Check if position is wall (1) or free (0)
lb $t5, 0($t4)
beq $t5, 1, collision_detected
# No collision - update player position
sw $t0, player_x
sw $t1, player_y
j end_movement
collision_detected:
# Don't move - stay at current position
j end_movement
end_movement:
jr $ra
Game Initialization & Main Loop
.data
bitmap: .word 0x10008000 # Address of the bitmap screen
keyboard: .word 0xffff0004 # Address to read keyboard input (ASCII code)
introMessage: .asciiz "Maze Runner - by Chris Greenblat. Use WASD to move"
# Screen layout system:
# Each screen/maze is an array of 32*32 elements (1024 total), filled with 1s and 0s.
# 1s represent walls or filled pixels.
# 0s represent open space or pathways.
maze: .word
1,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,
1,0,0,0,0,0,1,0,0,0,1,0,0,0,0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age
syscall
li $t6, 0 # Current pixel index
li $t7, 1024 # Max number of pixels (32x32)
lw $t0, bitmap # Load base address of bitmap
li $t4, 1024 # Pixel counter
la $s0, menuScreen # Load the menu screen layout
li $a3, 0 # Initial game state
li $t1, 0x4B0082 # Wall color (purple)
li $s1, 0xF0E68C # Space color (khaki)
setup:
# Draw the screen pixel by pixel based on values in screen array
beq $t6, $t7, choose
lw $a0, ($s0)
beq $a0, 1, drawWallColor
beq $a0, 0, drawSpaceColor
j setup
choose:
# Handle maze selection input and rerender the screen accordingly
la $s0, maze
beq $a3, 49, setupPlayer # ASCII '1'
la $s0, mazeTwo
beq $a3, 50, setupPlayer # ASCII '2'
beq $a3, 1, terminate
beq $a3, 2, terminate
lw $t8, keyboard # Load keyboard buffer
lw $t2, 0xffff0000 # Load keyboard status register
beq $t2, 0, choose # No key pressed yet
li $t6, 0 # Reset screen index
lw $t0, bitmap # Reload bitmap base
lw $a3, ($t8) # Get ASCII of pressed key
la $s0, maze
beq $a3, 49, setup # If key = '1'
la $s0, mazeTwo
li $t1, 0x228B22 # Wall color for maze 2 (forest green)
beq $a3, 50, setup # If key = '2'
j terminate
drawWallColor:
# Paint pixel as wall
sw $t1, ($t0)
addi $t4, $t4, -1
addi $t0, $t0, 4
addi $t6, $t6, 1
addi $s0, $s0, 4
j setup
drawSpaceColor:
# Paint pixel as space
sw $s1, ($t0)
addi $t4, $t4, -1
addi $t0, $t0, 4
addi $t6, $t6, 1
addi $s0, $s0, 4
j setup
setupPlayer:
# Place player and goal on screen
addi $s0, $s0, 4
lw $t0, bitmap
addi $t0, $t0, 4
li $t9, 0x00CED1 # Player color (dark turquoise)
sw $t9, ($t0)
li $t1, 0xFFD700 # Goal color (gold)
lw $t0, bitmap
addi $t0, $t0, 3836 # Hardcoded goal pixel offset
sw $t1, ($t0)
li $a3, 3836 # Track goal position
li $t1, 0xF0E68C # Restore space color (khaki)
lw $t0, bitmap
addi $t0, $t0, 4
li $t9, 0x00CED1 # Player color again
sw $t9, ($t0)
movePlayer:
# Movement loop: respond to WASD or 'r' inputs
lw $t8, keyboard
lw $t2, 0xffff0000
beq $t2, 0, movePlayer
lw $t3, ($t8)
beq $t3, 97, moveLeft # a
beq $t3, 119, moveBackwards # w
beq $t3, 115, moveForwards # s
beq $t3, 100, moveRight # d
beq $t3, 114, quit # r
j movePlayer
moveLeft:
# Move left if not wall
sw $t1, ($t0)
addi $t0, $t0, -4
sw $t9, ($t0)
addi $s0, $s0, -4
lw $a0, ($s0)
addi $a3, $a3, 4
beq $a0, 1, fail
beq $a3, 4, win
j movePlayer
moveForwards:
# Move down
sw $t1, ($t0)
addi $t0, $t0, 128
sw $t9, ($t0)
addi $s0, $s0, 128
lw $a0, ($s0)
addi $a3, $a3, -128
beq $a0, 1, fail
beq $a3, 4, win
j movePlayer
moveBackwards:
# Move up
sw $t1, ($t0)
addi $t0, $t0, -128
sw $t9, ($t0)
addi $s0, $s0, -128
lw $a0, ($s0)
addi $a3, $a3, 128
beq $a3, 3964, fail
beq $a0, 1, fail
beq $a3, 4, win
j movePlayer
moveRight:
# Move right
sw $t1, ($t0)
addi $t0, $t0, 4
sw $t9, ($t0)
addi $s0, $s0, 4
lw $a0, ($s0)
addi $a3, $a3, -4
beq $a0, 1, fail
beq $a3, 4, win
j movePlayer
win:
# Display win screen
li $s1, 0x00ff64 # Win screen space color (green)
lw $t0, bitmap
li $t6, 0
la $s0, winScreen
li $a3, 2
j setup
fail:
# Display fail screen
lw $t0, bitmap
li $t6, 0
la $s0, failScreen
li $t1, 0xB22222 # Fail screen wall color (firebrick)
li $a3, 1
j setup
quit:
# Display surrender screen
lw $t0, bitmap
li $t6, 0
li $t1, 0x1E90FF # Quit wall color (dodger blue)
li $a3, 1
j setup
terminate:
# End program
li $v0, 10
syscall
Quick Start Guide
How to Use the Simulator
- Load Code: Copy assembly code from the examples above
- Paste: Click in the editor and paste your code
- Assemble: Click "Compile" to assemble the code
- Run: Click "Continue" to execute the program
- Debug: Use "Step" to execute line by line
Sample Programs to Try
- Hello World: Basic output using syscalls
- Calculator: Simple arithmetic operations
- Loop Demo: For and while loop examples
- Maze Game: Use the code snippets above
Project Overview
Technical Implementation
- Memory Management: Efficient use of data segments for maze storage and game state
- Input Handling: Real-time keyboard input processing using MARS simulator
- Graphics: Bitmap display manipulation for visual maze representation
- Game Logic: Collision detection, boundary checking, and win condition evaluation
Challenges & Solutions
- Low-level Graphics: Manually drawing pixels and managing screen buffer
- State Management: Tracking player position and game state without high-level data structures
- Performance: Optimizing assembly code for smooth gameplay
- Debugging: Using MARS debugger to trace execution and fix logic errors
Project Stats
- Lines of Code: ~300 lines
- Development Time: 40+ hours
- Registers Used: $t0-$t9, $s0-$s7
- Memory Usage: ~2KB
- Platform: MARS MIPS Simulator
Learning Outcomes
This project provided deep insights into computer architecture and low-level programming. Working directly with assembly language taught me about CPU instruction cycles, memory addressing, register management, and the fundamental operations that higher-level languages abstract away. The experience of building a complete game without modern programming conveniences was both challenging and rewarding.
Future Enhancements
- Add multiple maze levels with increasing difficulty
- Implement a timer system for speedrun challenges
- Create procedurally generated mazes
- Add sound effects using MARS audio capabilities
- Implement a high score system with persistent storage
Experience the fundamentals of computer programming at the assembly level!