Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

. data X: . word 1 0 , 4 0 , 4 0 , 1 0 # Initial x - coordinates of robots Y: .

.data
X: .word 10,40,40,10 # Initial x-coordinates of robots
Y: .word 10,10,40,40 # Initial y-coordinates of robots
str1: .asciiz "Your coordinates: 2525
"
str2: .asciiz "Enter move (1 for +X,-1 for -X,2 for +Y,-2 for -Y): "
str3: .asciiz "Your coordinates: "
str4: .asciiz "Robot at "
str5: .asciiz "AAAARRRRGHHHHH... Game over
"
sp: .asciiz ""
endl: .asciiz "
"
.text
.globl main
main:
li $s1,25 # Player's initial X coordinate
li $s2,25 # Player's initial Y coordinate
li $s4,1 # Game status: 1= continue, 0= game over
la $a0, str1
li $v0,4
syscall
b main_while # Jump to main loop
main_while:
beq $s4,0, main_exit # If game over, exit the loop
# Display move options
la $a0, str2
li $v0,4
syscall
# Get player's move
li $v0,5
syscall
move $s3, $v0
# Update player's coordinates based on input
beq $s3,1, inc_x
beq $s3,-1, dec_x
beq $s3,2, inc_y
beq $s3,-2, dec_y
j main_while
inc_x:
addi $s1, $s1,1
j update_robots
dec_x:
addi $s1, $s1,-1
j update_robots
inc_y:
addi $s2, $s2,1
j update_robots
dec_y:
addi $s2, $s2,-1
j update_robots
update_robots:
# Update robot positions and check game status
la $a0, X
la $a1, Y
move $a2, $s1
move $a3, $s2
jal moveRobots
move $s4, $v0
# Print current coordinates of the player
la $a0, str3
li $v0,4
syscall
move $a0, $s1
li $v0,1
syscall
la $a0, sp
li $v0,4
syscall
move $a0, $s2
li $v0,1
syscall
la $a0, endl
li $v0,4
syscall
# Print current coordinates of the robots
la $t1, X
la $t2, Y
li $t0,0
print_robots:
bge $t0,4, end_print_robots
la $a0, str4
li $v0,4
syscall
lw $t3,0($t1) # Load robot X coordinate
move $a0, $t3
li $v0,1
syscall
la $a0, sp
li $v0,4
syscall
lw $t4,0($t2) # Load robot Y coordinate
move $a0, $t4
li $v0,1
syscall
la $a0, endl
li $v0,4
syscall
addi $t1, $t1,4 # Move to next robot X coordinate
addi $t2, $t2,4 # Move to next robot Y coordinate
addi $t0, $t0,1
j print_robots
end_print_robots:
j main_while # Repeat the loop
main_exit:
la $a0, str5 # Game over message
li $v0,4
syscall
li $v0,10 # Exit the program
syscall
moveRobots:
la $t5, X # Load base address of X
la $t6, Y # Load base address of Y
li $t0,0 # Loop counter
moveRobots_loop:
bge $t0,4, moveRobots_end # If loop counter >=4, end loop
lw $t3,0($t5) # Load current robot X coordinate
lw $t4,0($t6) # Load current robot Y coordinate
# Move robot X coordinate towards player
sub $t7, $a2, $t3 # $t7= player_x - robot_x
bltz $t7, dec_robot_x # If player_x robot_x, decrement robot_x
bgtz $t7, inc_robot_x # If player_x > robot_x, increment robot_x
inc_robot_x:
addi $t3, $t3,10
b store_robot_x
dec_robot_x:
addi $t3, $t3,-10
store_robot_x:
sw $t3,0($t5) # Store updated X coordinate
# Move robot Y coordinate towards player
sub $t7, $a3, $t4 # $t7= player_y - robot_y
bltz $t7, dec_robot_y # If player_y robot_y, decrement robot_y
bgtz $t7, inc_robot_y # If player_y > robot_y, increment robot_y
inc_robot_y:
addi $t4, $t4,10
b store_robot_y
dec_robot_y:
addi $t4, $t4,-10
store_robot_y:
sw $t4,0($t6) # Store updated Y coordinate
# Check if robot caught the human (X[i]== s1 && Y[i]== s2)
beq $t3, $a2, check_y_catch
b next_robot
check_y_catch:
beq $t4, $a3, human_dead
next_robot:
addi $t5, $t5,4 # Move to next robot X coordinate
addi $t6, $t6,4 # Move to next robot Y coordinate
addi $t0, $t0,1 # Increment loop counter
b moveRobots_loop
human_dead:
li $v0,0 # Game over
jr $ra
moveRobots_end:
li $v0,1 # Continue game
jr $ra
this is the code I have but it does not contain expected output .Can you please modify the above code according to this ouput .Please provide me every single line of the code.
image text in transcribed

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

SQL Instant Reference

Authors: Gruber, Martin Gruber

2nd Edition

0782125395, 9780782125399

More Books

Students also viewed these Databases questions