Also go to the top of the file. In the strings
MsyCR should be MsgCR
They should all be Msg____ <--- suffix
Also go to the top of the file. In the strings
MsyCR should be MsgCR
They should all be Msg____ <--- suffix
robot_state is an easy one!
It's in your Java code but you didn't define it here in your data!
robot_state: .word 0
Yeah I just found some other simple errors in the code I just fixed cause of typos.
Is this what I should change to MsgCR I changed the top one from msycr?
Error in Assembly2 line 203 position 10: Symbol "MsgCR" not found in symbol table.
Assemble: operation completed with errors.
When you get a chance drop this in
MsgFailsDestination: .asciiz "Robot fails to reach Destination\n"
!!! Right below this line! at the top of file
# Robot State Message Table
MsgRobotTbl: .word MsgRS1
.word MsgRS2
.word MsgRS3
.word MsgRS4
.word MsgRS5
it's a string table
I think its fixed now that I changed the msyCr
Error in Assembly2 line 227 position 15: Symbol "$LineB" not found in symbol table.
Assemble: operation completed with errors.
Error in Assembly2 line 38 position 1: label "MsgFailsDestination" already defined
Assemble: operation completed with errors.
Delete the last one! There's two sitting there!
the $LineB thing. Remove the $ on both of them. They're sitting side by side.
I fied the msgfailsdestination..i had it declared before
Error in Assembly2 line 246: Jump target word address beyond 26-bit range
Assemble: operation completed with errors.
Codes getting pretty long!
Change at the bottom of the file
#jgz MoveLoop # Loop 63 times for 64 iterations.
jgz MoveHop # Loop 63 times for 64 iterations.
Code is trying to jump too far!
So now we need to hop a bit
# Process new robot positiions! <-- fix spelling
j PrtOut
MoveHop: j MoveLoop
PrtOut: <-- Find this, and modify code above this line
to look like this
Essentially we need a double jump since one jump is too far.
We'll jump in the middle of the program at a safe place, then jump again!
Strange, doesn't seem like the code is THAT big!
]
bottom of file:
# Process new robot posit5ions!
PrtOut:
# System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
la $a0, MsgFinal
li $v0, 4 # specify Print String service
syscall # print heading
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 heading
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 heading
# System.out.println ("Robot State: ");
la $t0,robot_x
lw $t0,0($t0) # $t0 = robot_x
la $t5,robot_y
# lw $t5,0($t1) # $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
# register to register compares
# 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,LineA3 # jump if robot_y == 2
beq $t5,$t2,LineAOK # jump if robot_y == 2
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 heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
#jgz MoveLoop # Loop 63 times for 64 iterations.
jgz MoveHop # Loop 63 times for 64 iterations.
# Process new robot positions
j PrtOut
MoveHop: j MoveLoop
PrtOut:
# Process new robot positiions! <-- fix spelling j PrtOut MoveHop: j MoveLoop PrtOut: <-- Find this, and modify code above this line to look like this
Done:
# Next conditional line
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
LineB:
add $t7, $t7, 4
add $t6, $t6, -1
bgtz $a0, MoveLoop # Loop 64 times
jr $ra # return
Error in Assembly2 line 244 position 1: "jgz" directive cannot appear in text segment
Error in Assembly2 line 253 position 1: label "PrtOut" already defined
Assemble: operation completed with errors.
Yep
#jgz MoveLoop # Loop 63 times for 64 iterations.
jgz MoveHop # Loop 63 times for 64 iterations.
Should be removed!
That second PrtOut:
should be removed!
MoveHop: j MoveLoop
PrtOut: <--- Delete this line
Any code that has the # in front of is commented out code and should be eventualy removed!
Once you get a clean assemble, compare the following code.
It should look like this!
# ______________________________
# register to register compares
# 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
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 heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
j Done
# ______________________________
# Next conditional line
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
LineB:
j Done
Line C:
j Done
Line D:
j Done
Done:
Note the Java comment in Line A and how each condition was handled.
It will be up to you to try to recreate the Line B version
Line C, and Line D versions!
Each Line# is a conditional line that was in your Java.
Everything you need is there! Just examine how Line A code block works.
ok it compiled. but it doesn't print anything it keeps going through line 60-65
ok i'm doing b, c, d now
Hmm!
# Clear Entire Maze Array
la $t0, maze # load address of maze
li $t3, 2 # <-- Fill maze with (2)
li $t1, 144
clr: # repeat if not finished yet.
# la $t0, maze # base address <---- DELETE THIS LINE!
It keeps resetting the pointer back to the base!
#### li $t3, 2 # maze[i] = 2 <-- this one too!
sb $t3, 0($t0)
add $t0, $t0, 1 # address++
add $t1, $t1, -1 # count--
bgtz $t1, clr
So is the maze suppose to be pre-filled with 0's or 2's?
0's
The clear matrix should look like this then...
# Clear Entire Maze Array
la $t0, maze # load address of maze
li $t3, 0 # <-- Fill maze with (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
I just wanted to chekc with you before I kept going:
# register to register compares
# 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
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 heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
# Process new robot positions
j PrtOut
MoveHop: j MoveLoop
Done:
# Next conditional line
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
bne $t0,$t1,LineB # jump if robot_x <> 2
beq $t5,$t2,LineBOK # jump if robot_y == 3
LineB: # || ( (robot_x == 2) && (robot_y == 4)) )
bne $t0,$t2,LineC
bne $t5,$t4,LineC
LineBOK: #SUCCESS
la $a0, MsgFallenTrap
li $vo, 4
syscal
la $a0, robot_state
sw $t2, 0 ($a0) #robot_state=2
j prtOut
MoveHop: j MoveLoop
j Done
Done: Should be near bottom of file just above the robot_state 4 case code that doesn't exist yet!
# Process new robot positions
j PrtOut
MoveHop: j MoveLoop
Done:
# Next conditional line
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
!!!! Remember $t0 is robot_x $t5 is robot_y
!!!! $t1=(1) $t2=(2) $t3=(3) $t4=(4)
!!! this line comment is correct, code isn't! You have wrong immedate value, and you aren't jumping to 2nd half of this line! Remember you had ( A & B ) || (C & D) So only 1/2 has to be true to be successful! So if first half fails, then check the second half.
Re-examine conditionals and your branching. I'm shutting down in a couple minutes to head for home, etc. But...
1st Conditional Line
LineA:
if (A <> #) then go to 2nd half Line A3
if (B == #) Then go to succss for LineA LineAOK
LineA3:
if (C <> #) then go to Line B we totally lose
if (D <> #) then go to Line B we also lose
LineAOK: WINNER
Do our stuff
then jump past everything to DONE which is robot_state case
--------
Line B
For Line B we do same as Line A with new sets of #'s.
------
Line C
Same again
------
Line D
Same again
Done: We are now at robot_state printing!
----------------
Okay review my comments as to your code...
for Line B
bne $t0,$t1,LineB # jump if robot_x <> 2
!!!Comment is correct Code is not!
beq $t5,$t2,LineBOK # jump if robot_y == 3
LineB: # || ( (robot_x == 2) && (robot_y == 4)) )
bne $t0,$t2,LineC # <--- Good
bne $t5,$t4,LineC # <--- Good
LineBOK: #SUCCESS
la $a0, MsgFallenTrap
li $vo, 4
syscal
la $a0, robot_state
sw $t2, 0 ($a0) #robot_state=2
j prtOut ????
!!! remember we keep flowing dowards. In Java it was if else if elseif else
So Need to jump past the other else's to the robot_state case statement code!
j Done
.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 256
# 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]
sb $t1, 0x34($t0) # maze[3][4]
li $t1, 4 #iDESTINATION: # maze[3][2] = 4;
sb $t1, 0x32($t0) # 1 x 16 + 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
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}
sw $a0,0($t7) # robot_instructions[i] = rnd{ 1...4 }
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 PrtOut
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 PrtOut
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 PrtOut
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
# Process new robot posit5ions!
PrtOut:
# System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
la $a0, MsgFinal
li $v0, 4 # specify Print String service
syscall # print heading
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 heading
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 heading
# System.out.println ("Robot State: ");
la $t0,robot_x
lw $t0,0($t0) # $t0 = robot_x
la $t5,robot_y
# lw $t5,0($t1) # $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
# register to register compares
# 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
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 heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
# Process new robot positions
j PrtOut
MoveHop: j MoveLoop
# Next conditional line
# Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
bne $t0,$t2,LineB # jump if robot_x <> 2
beq $t5,$t3,LineBOK # jump if robot_y == 3
LineB: # || ( (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 $t2, 0 ($a0) #robot_state=3
j MoveLoop
j Done
# register to register compares
# Ref: if ((robot_x == 3) && (robot_y == 2))
bne $t0,$t3,LineC # jump if robot_x <> 3
beq $t5,$t2,LineC # jump if robot_y == 2
LineCOK: # SUCCESS
la $a0, MsgReachedDestination
li $v0, 4 # specify Print String service
syscall # print heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 4
# Process new robot positions
j PrtOut
j MoveLoop
j Done
LineDOK: # SUCCESS
la $a0, MsgSafePlace
li $v0, 4 # specify Print String service
syscall # print heading
la $a0, robot_state
sw $t2,0($a0) # robot_state = 1
# Process new robot positions
j PrtOut
Done:
jr $ra # return
Error in Assembly2 line 262 position 4: "$vo": operand is of incorrect type
Error in Assembly2 line 263 position 1: "syscal" directive cannot appear in text segment
Assemble: operation completed with errors.
Since this is no longer a school project I went in and cleaned top to bottom. You need to finish at bottom where indicated.
Review each section of code and understand how it works!
.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
Error in Assembly2 line 260 position 5: "$vo": operand is of incorrect type
Error in Assembly2 line 261 position 2: "syscal" directive cannot appear in text segment
Error in Assembly2 line 277 position 5: "$vo": operand is of incorrect type
Error in Assembly2 line 278 position 2: "syscal" directive cannot appear in text segment
Assemble: operation completed with errors.
#robot_state print
Done:
la $a0, robot_state
lw $t0,0($a0) # to is robot_state
la $a0, robot_state
sw $t4,0($a0) # robot_state = 1
syscall
la $a0, robot_state
sw $t2,0($a0) # robot_state = 2
syscall
la $a0, robot_state
sw $t3, 0 ($a0) #robot_state=3
syscall
la $a0, robot_state
sw $t4, 0 ($a0) #robot_state=4
syscall
Error in Assembly2 line 260 position 5: "$vo": operand is of incorrect type
Error in Assembly2 line 261 position 2: "syscal" directive cannot appear in text segment
Error in Assembly2 line 277 position 5: "$vo": operand is of incorrect type
Error in Assembly2 line 278 position 2: "syscal" directive cannot appear in text segment
Assemble: operation completed with errors.
oops typo on the syscall*
But I can't figure out the error in this:
Error in Assembly2 line 260 position 5: "$vo": operand is of incorrect type
Error in Assembly2 line 277 position 5: "$vo": operand is of incorrect type
Assemble: operation completed with errors.
I missed it change those two syscal to syscall
Change $vo to $v0 zero
You print the four robot_state lines but you aren't printing based upon if 1 or 2 or 3 or 4.
So without using conditionals, try this instead!
It uses the robot_state as an index into a string table and prints the appropriate string for states 1...5
Done:
la $a0, robot_state
lw $t0,0($a0) # is state 1...5
add $t0,$t0,-1 # state is 0...4
sll $t0,$t0,2 # x4 0,4,8,12,16 Address offset
# ASCIIz table lookup
la $a0, MsgRobotTbl # table base
add $a0, $a0, $t0
lw $a0,0($a0)
li $vo, 4
syscal #print ASCIIz MsgRobotTbl[ robot_state ]
There's probaby bugs but you should try to find them yourself by single steping the code and watching the values in the registers. If you have compile errors, look for typos, like those last errors you posted!
When you get curious enough, find the line count for your Java program and find the line count for this assembly file. Notice the difference! That's why these days higher level languages are used for application building and not assembly language. Assembly is left for specialty applications like drivers, and math libraries, etc.
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.