Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Help me fix any problems in my MIPS / MARS code, in order to get the game to properly run. I have been struggling with

Help me fix any problems in my MIPS/MARS code, in order to get the game to properly run. I have been struggling with this for weeks so helping will be appreciated. Thanks!
moveRobots:
addi $sp, $sp,-4
sw $ra,0($sp)
li $t0,0
move_loop:
bge $t0,4, end_move_loop
li $t1,0
mul $t2, $t0,4
add $t2, $a0, $t2
lw $t3,0($t2)
add $t2, $a1, $t2
lw $t4,0($t2)
move $a0, $t3
move $a1, $a2
jal getNew
move $t3, $v0
move $a0, $t4
move $a1, $a3
jal getNew
move $t4, $v0
beq $t3, $a2, human_dead
beq $t4, $a3, human_dead
addi $t0, $t0,1
j move_loop
end_move_loop:
li $v0,1
j moveRobots_exit
human_dead:
li $v0,0
moveRobots_exit:
lw $ra,0($sp)
addi $sp, $sp,4
jr $ra
getNew:
addi $sp, $sp,-4
sw $ra,0($sp)
sub $v0, $a0, $a1
lw $ra,0($sp)
addi $sp, $sp,4
jr $ra
.text
main:
addi $sp, $sp,-12
sw $ra,0($sp)
sw $s0,4($sp)
sw $s1,8($sp)
li $s0,25
li $s1,25
la $a0, x
la $a1, y
main_loop:
li $v0,4
la $a0, user_coords
syscall
li $v0,4
la $a0, prompt_input
syscall
li $v0,5
syscall
beq $v0,1, move_right
beq $v0,-1, move_left
beq $v0,2, move_up
beq $v0,-2, move_down
j invalid_input
move_right:
addi $s0, $s0,1
j update_robots
move_left:
addi $s0, $s0,-1
j update_robots
move_up:
addi $s1, $s1,1
j update_robots
move_down:
addi $s1, $s1,-1
j update_robots
invalid_input:
li $v0,4
la $a0, invalid_input_msg
syscall
j main_loop
update_robots:
move $a2, $s0
move $a3, $s1
jal moveRobots
move $t0, $v0
beq $t0,0, human_dead
j main_loop
move_end:
lw $ra,0($sp)
lw $s0,4($sp)
lw $s1,8($sp)
addi $sp, $sp,12
li $v0,10
syscall
.data
x: .space 40
y: .space 40
user_coords: .asciiz "Your coordinates: "
prompt_input: .asciiz "Enter move (1 for +x,-1 for -x,2 for +y,-2 for -y): "
invalid_input_msg: .asciiz "Invalid input! Please enter 1,-1,2, or -2.
"
game_over_msg: .asciiz "AAAARRRRGHHHHH... Game over
"

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

The Accidental Data Scientist

Authors: Amy Affelt

1st Edition

1573877077, 9781573877077

More Books

Students also viewed these Databases questions

Question

Describe three forms of conflict from the work of Lewin.

Answered: 1 week ago