Answered step by step
Verified Expert Solution
Question
1 Approved Answer
# # A proper program header goes here... # # . data x: . word 0 : 4 # x - coordinates of 4 robots
#
# A proper program header goes here...
#
#
data
x: word : # xcoordinates of robots
y: word : # ycoordinates of robots
str: asciiz "Your coordinates:
str: asciiz "Enter move for x for x for y for y:
str: asciiz "Your coordinates:
sp: asciiz
endl: asciiz
str: asciiz "Robot at
str: asciiz "AAAARRRRGHHHHH... Game over
#i $s
#myX $s
#myY $s
#move $s
#status $s
#temp,pointers $s$s
text
# globl inc
# globl getNew
main: li $s # myX
li $s # myY
li $s # status
la $sx
la $sy
sw $$s # x; y;
sw $$s
sw $$s # x; y;
li $s
sw $s$s
sw $s$s # x; y;
sw $$s
sw $s$s # x; y;
sw $s$s
la $astr # cout "Your coordinates:
;
li $v
syscall
bne $smainexitw # while status
mainwhile:
la $astr # cout "Enter move for x
li $v # for x for y for y:;
syscall
li $v # cin move;
syscall
move $s$v
bne $smainelse# if move
add $s$s # myX;
b mainexitif
mainelse:
bne $smainelse # else if move
add $s$s # myX;
b mainexitif
mainelse:
bne $smainelse # else if move
add $s$s # myY;
b mainexitif
mainelse: bne $smainexitif # else if move
add $s$s # myY;
mainexitif: la $ax # status moveRobots&x&ymyXmyY;
la $ay
move $a$s
move $a$s
jal moveRobots
move $s$v
la $astr # cout "Your coordinates: myX
li $v # myY endl;
syscall
move $a$s
li $v
syscall
la $asp
li $v
syscall
move $a$s
li $v
syscall
la $aendl
li $v
syscall
la $sx
la $sy
li $s # for i;i;i
mainfor: la $astr # cout "Robot at xi
li $v # yi endl;
syscall
lw $a$s
li $v
syscall
la $asp
li $v
syscall
lw $a$s
li $v
syscall
la $aendl
li $v
syscall
add $s$s
add $s$s
add $s$s
blt $smainfor
beq $smainwhile
#
mainexitw: la $astr # cout "AAAARRRRGHHHHH... Game over
;
li $v
syscall
li $v #
syscall
# int moveRobotsint arg int arg int arg int arg
#
# arg $a base address of array of xcoordinates
# arg $a base address of array of ycoordinates
# arg $a xcoordinate of human copy in $s
# arg $a ycoordinate of human copy in $s
# ptrX $s
# ptrY $s
# i $s
# alive $s
# temp $s
#
# moveRobots calls getNew to obtain the new coordinates
# of each robot. The position of each robot is updated.
moveRobots:
li $s # alive ;
move $s$a
move $s$a
move $s$a # ptrX arg;
move $s$a # ptrY arg;
li $s # for i;i;i
loop: # ptrX getNewptrXarg; input we use $a$a
#jal getNew return value we use $v
#the return value of getNew is saved in $v
# ptrY getNewptrYarg;
# if ptrX arg && ptrY arg
#
# alive ;
j endfor # break;
#
inc: # ptrX;
# ptrY;
#
endfor: # return alive;
jr $ra #
# int getNewint arg int arg
#
# arg $a one coordinate of robot
# arg $a one coordinate of human
# temp $t
# result $v
#
# Returns new coordinate of robot. If the absolute difference between
# the robot coordinate and human coordinate is the robot
# coordinate moves units closer to the human coordinate.
# If the absolute difference is the robot coordinate
# moves unit closer to the human coordinate.
getNew: #
sub $t$a$a # temp arg arg;
blt $tgelse # if temp
sub $v$a # result arg;
j exitgelse
gelse: blez $tgelse # else if temp
sub $v$a # result arg;
j exitgelse
gelse: # else if temp
# result arg;
gelse: # else if temp
# result arg;
gelse: bgt $texitgelse # else if temp
add $v$a # result arg;
exitgelse:
jr $ #
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started