Since this is no longer a school project I went in and cleaned top to bottom. You need to finish at bottom where indicated.
.data # variable declarations follow this line
iSAFE: 1
iCHASM: 2
iTRAP: 3
iDESTINATION: 4
maze: .space 144 # 9x9 stored in a 16x9 buffer
robot_x: .word 0
robot_y: .word 0
robot_m_x: .word 0
robot_m_y: .word 0
robot_state: .word 0
robot_instructions: .space 64
# Robot State Message Table
MsgRobotTbl:
.word MsgRS1
.word MsgRS2
.word MsgRS3
.word MsgRS4
.word MsgRS5
MsgFailsDestination: .asciiz "Robot fails to reach Destination\n"
MsgRS1: .asciiz "Robot is at a safe place\n"
MsgRS2: .asciiz "Robot falls into Chasm\n"
MsgRS3: .asciiz "Robot falls into the trap\n"
MsgRS4: .asciiz "Robot reaches Destination\n"
MsgRS5: .asciiz "Robot fails to reach Destination\n"
MsgFinal: .asciiz "Robot final location X: "
MsgY: .asciiz " Y: "
MsgCR: .asciiz "\n"
MsgRobotState: .asciiz "Robot State: \n"
MsgFallenChasm: .asciiz "Robot has fallen into a chasm\n"
MsgFallenTrap: .asciiz "Robot has fallen into a trap\n"
MsgReachedDestination: .asciiz "Robot has reached Destination\n"
MsgSafePlace: .asciiz "Robot is at a safe place\n"
MsgFallsChasm: .asciiz "Robot falls into Chasm\n"
MsgFallsTrap: .asciiz "Robot falls into the trap\n"
MsgReachesDestination: .asciiz "Robot reaches Destination\n"
.text # CODE SECTION OF ASM FILE
#main:
li $v0,30 # Get time
syscall # CMD: Get Time
# $a0 = lower 32-bits, $a1=upper 32-bits
# Seed RNG (Random Number Generator)
move $a1,$a0 # get lower 32-bit time as seed
li $a0,0 # Rng#0
syscall # CMD: Seed the RNG
# Clear Entire Maze Array
la $t0, maze # address of maze
li $t3, 0
li $t1, 144
clr: # repeat if not finished yet.
sb $t3, 0($t0)
add $t0, $t0, 1 # address++
add $t1, $t1, -1 # count--
bgtz $t1, clr
# _______________
# Setup variables
la $t0, maze # base address
li $t1,1 # iSAFE:
sb $t1, 0x11($t0) # maze[1][1] = 1;
li $t1,2 # iCHASM:
sb $t1, 0x12($t0) # maze[1][2] = 2
sb $t1, 0x24($t0) # maze[2][4] = 2
li $t1, 3 #iTRAP:
sb $t1, 0x23($t0) # maze[2][3] = 3
sb $t1, 0x34($t0) # maze[3][4] = 3
li $t1, 4 #iDESTINATION:
sb $t1, 0x32($t0) # maze[3][2] = 4;
# robot_x = 1
la $t0,robot_x
li $t1,1
sw $t1,0($t0)
# robot_y = 2
la $t0,robot_y
li $t1,2
sw $t1,0($t0)
# init robot_state = 5
la $t0,robot_state
li $t1,5
sw $t1,0($t0)
la $t7,robot_instructions # index
li $t6,64 # Num of loops
# _______________
# TOP of BIG Loop
MoveLoop:
# Get a Random #
li $a0, 0 # Rng#
li $a1, 4 # rand() %4 {0...3}
li $v0, 42
syscall # Get RNG
# $a0 = {0...3}
add $a0, $a0, 1 # {1...4}
# Store Robot instruction
sb $a0,0($t7) # robot_instructions[i] = rnd{ 1...4 }
add $t7, $t7, 1 # increment address
add $a0, $a0, -1
bgtz $a0, RJump
# ____________
# case 1: MOVE
la $t1,robot_m_x
la $t0,robot_x
lw $t2,0($t1)
sw $t2,0($t0) # robot_x = robot_m_x
la $t1,robot_m_y
la $t0,robot_y
lw $t2,0($t1)
add $t2,$t2,1
sw $t2,0($t0) # robot_y = robot_m_y + 1
j Processing # Goto Processing
RJump:
add $a0, $a0, -1
bgtz $a0, RLeft
# ____________
# case 2: Jump
la $t1,robot_m_x
la $t0,robot_x
lw $t2,0($t1)
sw $t2,0($t0) # robot_x = robot_m_x
la $t1,robot_m_y
la $t0,robot_y
lw $t2, 0($t1)
add $t2, $t2, 2
sw $t2, 0($t0) # robot_y = robot_m_y + 2
j Processing # Goto Processing
RLeft:
add $a0, $a0, -1
bgtz $a0, RRight
# ____________
# case 3: Left
la $t1,robot_m_x
la $t0,robot_x
lw $t2,0($t1)
add $t2, $t2, -1
sw $t2,0($t0) # robot_x = robot_m_x - 1
j Processing # Goto Processing
# _____________
# case 4: Right
RRight:
la $t1,robot_m_x
la $t0,robot_x
lw $t2,0($t1)
add $t2, $t2, 1
sw $t2,0($t0) # robot_x = robot_m_x + 1
# ______________________________
# Processing new robot positions!
Processing:
# System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
la $a0, MsgFinal
li $v0, 4 # specify Print String service
syscall # print ASCIIz
la $t0,robot_x
lw $a0,0($t0)
li $v0, 1
syscall # CMD: print robot_x integer
la $a0, MsgY
li $v0, 4 # specify Print String service
syscall # print ASCIIz
la $t0,robot_y
lw $a0,0($t0)
li $v0, 1
syscall # CMD: print robot_Y integer
la $a0, MsgCR
li $v0, 4 # specify Print String service
syscall # print CRLF
# System.out.println ("Robot State: ");
la $t0,robot_x
lw $t0,0($t0) # $t0 = robot_x
la $t5,robot_y
lw $t5,0($t5) # $t5 = robot_y
# Using $t1 ... $t4 since they look similar to 1...4
li $t1,1
li $t2,2
li $t3,3
li $t4,4
# _____________________________________________________________________________________
# Ref: if (( (robot_x == 1) && (robot_y == 2)) || ( (robot_x == 2) && (robot_y == 4)) )
bne $t0,$t1,LineA3 # jump if robot_x <> 1
beq $t5,$t2,LineAOK # jump if robot_y == 2 * Success *
LineA3: # || ( (robot_x == 2) && (robot_y == 4)) )
bne $t0,$t2, LineB #jump if robot_x <> 2
bne $t5,$t4, LineB #jump if robot_y <> 4
LineAOK: # SUCCESS
la $a0, MsgFallenChasm
li $v0, 4 # specify Print String service
syscall # print ASCIIz
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
# Process new robot positions
j Done
MoveHop: j MoveLoop # HOP to top of loop
# ____________________________________________________________________________________
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
LineB:
bne $t0,$t2,LineB3 # jump if robot_x <> 2
beq $t5,$t3,LineBOK # jump if robot_y == 3 * Success *
LineB3: # || ( (robot_x == 2) && (robot_y == 4)) )
bne $t0,$t3, LineC #jump if robot_x <> 3
bne $t5,$t4, LineC #jump if robot_y <> 4
LineBOK: # SUCCESS
la $a0, MsgFallenTrap
li $vo, 4
syscal #print heading
la $a0, robot_state
sw $t3, 0 ($a0) #robot_state=3
j Done
# ___________________________________________
# Ref: if ((robot_x == 3) && (robot_y == 2))
LineC:
bne $t0,$t3, LineD # jump if robot_x <> 3
bne $t5,$t2, LineD # jump if robot_y <> 2
# SUCCESS
la $a0, MsgReachedDestination
li $vo, 4
syscal #print ASCIIz
la $a0, robot_state
sw $t4, 0 ($a0) #robot_state=4
j Done
# _________________________________________
LineD:
la $a0, MsgSafePlace
li $v0, 4 # specify Print String service
syscall # print ASCIIz
la $a0, robot_state
sw $t4,0($a0) # robot_state = 1
# ___________________
# Print Robot State
Done:
la $a0, robot_state
lw $t0,0($a0) # to is robot_state
### <--- Insert 4 case robot_state printing!
# ________
# End Loop
add $t6, $t6, -1 # count--
bgtz $t1, MoveHop # Hop back to top of big loop
jr $ra # return