Java to Assembly

Thread Solved

Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Java to Assembly

 
0
  #141
Aug 14th, 2009
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
Last edited by wildgoose; Aug 14th, 2009 at 11:59 pm.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #142
Aug 15th, 2009
  1.  
  2. .data # variable declarations follow this line
  3. iSAFE: 1
  4. iCHASM: 2
  5. iTRAP: 3
  6. iDESTINATION: 4
  7.  
  8. maze: .space 144 # 9x9 stored in a 16x9 buffer
  9. robot_x: .word 0
  10. robot_y: .word 0
  11. robot_m_x: .word 0
  12. robot_m_y: .word 0
  13. robot_state: .word 0
  14. robot_instructions: .space 256
  15.  
  16. # Robot State Message Table
  17. MsgRobotTbl:
  18. .word MsgRS1
  19. .word MsgRS2
  20. .word MsgRS3
  21. .word MsgRS4
  22. .word MsgRS5
  23. MsgFailsDestination: .asciiz "Robot fails to reach Destination\n"
  24.  
  25. MsgRS1: .asciiz "Robot is at a safe place\n"
  26. MsgRS2: .asciiz "Robot falls into Chasm\n"
  27. MsgRS3: .asciiz "Robot falls into the trap\n"
  28. MsgRS4: .asciiz "Robot reaches Destination\n"
  29. MsgRS5: .asciiz "Robot fails to reach Destination\n"
  30. MsgFinal: .asciiz "Robot final location X: "
  31. MsgY: .asciiz " Y: "
  32. MsgCR: .asciiz "\n"
  33. MsgRobotState: .asciiz "Robot State: \n"
  34. MsgFallenChasm: .asciiz "Robot has fallen into a chasm\n"
  35. MsgFallenTrap: .asciiz "Robot has fallen into a trap\n"
  36. MsgReachedDestination: .asciiz "Robot has reached Destination\n"
  37. MsgSafePlace: .asciiz "Robot is at a safe place\n"
  38. MsgFallsChasm: .asciiz "Robot falls into Chasm\n"
  39. MsgFallsTrap: .asciiz "Robot falls into the trap\n"
  40. MsgReachesDestination: .asciiz "Robot reaches Destination\n"
  41.  
  42. .text # CODE SECTION OF ASM FILE
  43.  
  44. #main:
  45. li $v0,30 # Get time
  46. syscall # CMD: Get Time
  47. # $a0 = lower 32-bits, $a1=upper 32-bits
  48.  
  49. # Seed RNG (Random Number Generator)
  50. move $a1,$a0 # get lower 32-bit time as seed
  51. li $a0,0 # Rng#0
  52. syscall # CMD: Seed the RNG
  53.  
  54.  
  55. # Clear Entire Maze Array
  56.  
  57. la $t0, maze # address of maze
  58. li $t3, 0
  59. li $t1, 144
  60.  
  61. clr: # repeat if not finished yet.
  62. sb $t3, 0($t0)
  63. add $t0, $t0, 1 # address++
  64. add $t1, $t1, -1 # count--
  65. bgtz $t1, clr
  66.  
  67.  
  68. # Setup variables
  69. la $t0, maze # base address
  70.  
  71.  
  72. li $t1,1 # iSAFE:
  73. sb $t1,0x11($t0) # maze[1][1] = 1;
  74.  
  75.  
  76. li $t1,2 # iCHASM:
  77. sb $t1, 0x12($t0) # maze[1][2] = 2
  78. sb $t1,0x24($t0) # maze[2][4] = 2
  79.  
  80. li $t1, 3 #iTRAP:
  81. sb $t1, 0x23($t0) # maze[2][3]
  82. sb $t1, 0x34($t0) # maze[3][4]
  83.  
  84.  
  85. li $t1, 4 #iDESTINATION: # maze[3][2] = 4;
  86. sb $t1, 0x32($t0) # 1 x 16 + 4
  87.  
  88. # robot_x = 1
  89. la $t0,robot_x
  90. li $t1,1
  91. sw $t1,0($t0)
  92.  
  93. # robot_y = 2
  94. la $t0,robot_y
  95. li $t1,2
  96. sw $t1,0($t0)
  97.  
  98. # init robot_state = 5
  99. la $t0,robot_state
  100. li $t1,5
  101. sw $t1,0($t0)
  102.  
  103. la $t7,robot_instructions # index
  104. li $t6,64
  105.  
  106. MoveLoop:
  107.  
  108.  
  109. # Get a Random #
  110.  
  111. li $a0, 0 # Rng#
  112. li $a1, 4 # rand() %4 {0...3}
  113. li $v0, 42
  114. syscall # Get RNG
  115. # $a0 = {0...3}
  116. add $a0, $a0, 1 # {1...4}
  117.  
  118. sw $a0,0($t7) # robot_instructions[i] = rnd{ 1...4 }
  119.  
  120. add $a0, $a0, -1
  121. bgtz $a0, RJump
  122.  
  123. # case 1: MOVE
  124.  
  125. la $t1,robot_m_x
  126. la $t0,robot_x
  127.  
  128. lw $t2,0($t1)
  129. sw $t2,0($t0) # robot_x = robot_m_x
  130.  
  131. la $t1,robot_m_y
  132. la $t0,robot_y
  133. lw $t2,0($t1)
  134. add $t2,$t2,1
  135. sw $t2,0($t0) # robot_y = robot_m_y + 1
  136.  
  137. j PrtOut
  138.  
  139.  
  140. RJump:
  141. add $a0, $a0, -1
  142. bgtz $a0, RLeft
  143.  
  144. # case 2: Jump
  145.  
  146. la $t1,robot_m_x
  147. la $t0,robot_x
  148.  
  149. lw $t2,0($t1)
  150. sw $t2,0($t0) # robot_x = robot_m_x
  151.  
  152. la $t1,robot_m_y
  153. la $t0,robot_y
  154. lw $t2, 0($t1)
  155. add $t2, $t2, 2
  156. sw $t2, 0($t0) # robot_y = robot_m_y + 2
  157.  
  158. j PrtOut
  159.  
  160.  
  161. RLeft:
  162. add $a0, $a0, -1
  163. bgtz $a0, RRight
  164.  
  165. # case 3: Left
  166.  
  167. la $t1,robot_m_x
  168. la $t0,robot_x
  169. lw $t2,0($t1)
  170. add $t2, $t2, -1
  171. sw $t2,0($t0) # robot_x = robot_m_x - 1
  172.  
  173.  
  174. j PrtOut
  175.  
  176. RRight:
  177.  
  178. la $t1,robot_m_x
  179. la $t0,robot_x
  180. lw $t2,0($t1)
  181. add $t2, $t2, 1
  182. sw $t2,0($t0) # robot_x = robot_m_x + 1
  183.  
  184. # Process new robot posit5ions!
  185.  
  186. PrtOut:
  187. # System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
  188.  
  189. la $a0, MsgFinal
  190. li $v0, 4 # specify Print String service
  191. syscall # print heading
  192.  
  193. la $t0,robot_x
  194. lw $a0,0($t0)
  195. li $v0, 1
  196. syscall # CMD: print robot x integer
  197.  
  198. la $a0, MsgY
  199. li $v0, 4 # specify Print String service
  200. syscall # print heading
  201.  
  202. la $t0,robot_y
  203. lw $a0,0($t0)
  204. li $v0, 1
  205. syscall # CMD: print robot Y integer
  206.  
  207. la $a0, MsgCR
  208. li $v0, 4 # specify Print String service
  209. syscall # print heading
  210.  
  211. # System.out.println ("Robot State: ");
  212. la $t0,robot_x
  213. lw $t0,0($t0) # $t0 = robot_x
  214. la $t5,robot_y
  215. # lw $t5,0($t1) # $t5 = robot_y
  216. lw $t5,0($t5) # $t5 = robot_y
  217.  
  218. # Using $t1 ... $t4 since they look similar to 1...4
  219. li $t1,1
  220. li $t2,2
  221. li $t3,3
  222. li $t4,4
  223.  
  224. # register to register compares
  225. # Ref: if (( (robot_x == 1) && (robot_y == 2)) || ( (robot_x == 2) && (robot_y == 4)) )
  226. bne $t0,$t1,LineA3 # jump if robot_x <> 1
  227. beq $t5,$t2,LineAOK # jump if robot_y == 2
  228.  
  229. LineA3: # || ( (robot_x == 2) && (robot_y == 4)) )
  230. bne $t0,$t2, LineB #jump if robot_x <> 2
  231. bne $t5,$t4, LineB #jump if robot_y <> 4
  232.  
  233. LineAOK: # SUCCESS
  234.  
  235. la $a0, MsgFallenChasm
  236. li $v0, 4 # specify Print String service
  237. syscall # print heading
  238.  
  239. la $a0, robot_state
  240. sw $t2,0($a0) # robot_state = 2
  241.  
  242. # Process new robot positions
  243.  
  244. j PrtOut
  245.  
  246. MoveHop: j MoveLoop
  247.  
  248. # Next conditional line
  249. # Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
  250. bne $t0,$t2,LineB # jump if robot_x <> 2
  251. beq $t5,$t3,LineBOK # jump if robot_y == 3
  252.  
  253.  
  254. LineB: # || ( (robot_x == 2) && (robot_y == 4)) )
  255.  
  256. bne $t0,$t3,LineC #jump if robot_x <> 3
  257. bne $t5,$t4, LineC #jump if robot_y <> 4
  258.  
  259.  
  260. LineBOK: #SUCCESS
  261.  
  262. la $a0, MsgFallenTrap
  263. li $vo, 4
  264. syscal#print heading
  265. la $a0, robot_state
  266. sw $t2, 0 ($a0) #robot_state=3
  267.  
  268. j MoveLoop
  269.  
  270. j Done
  271.  
  272.  
  273.  
  274. # register to register compares
  275. # Ref: if ((robot_x == 3) && (robot_y == 2))
  276. bne $t0,$t3,LineC # jump if robot_x <> 3
  277. beq $t5,$t2,LineC # jump if robot_y == 2
  278.  
  279.  
  280. LineCOK: # SUCCESS
  281.  
  282. la $a0, MsgReachedDestination
  283. li $v0, 4 # specify Print String service
  284. syscall # print heading
  285.  
  286. la $a0, robot_state
  287. sw $t2,0($a0) # robot_state = 4
  288.  
  289. # Process new robot positions
  290.  
  291. j PrtOut
  292.  
  293. j MoveLoop
  294.  
  295.  
  296. j Done
  297.  
  298.  
  299. LineDOK: # SUCCESS
  300.  
  301. la $a0, MsgSafePlace
  302. li $v0, 4 # specify Print String service
  303. syscall # print heading
  304.  
  305. la $a0, robot_state
  306. sw $t2,0($a0) # robot_state = 1
  307.  
  308. # Process new robot positions
  309.  
  310. j PrtOut
  311.  
  312.  
  313. Done:
  314.  
  315.  
  316. jr $ra # return
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #143
Aug 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Java to Assembly

 
1
  #144
Aug 15th, 2009
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!

  1. .data # variable declarations follow this line
  2. iSAFE: 1
  3. iCHASM: 2
  4. iTRAP: 3
  5. iDESTINATION: 4
  6.  
  7. maze: .space 144 # 9x9 stored in a 16x9 buffer
  8. robot_x: .word 0
  9. robot_y: .word 0
  10. robot_m_x: .word 0
  11. robot_m_y: .word 0
  12. robot_state: .word 0
  13. robot_instructions: .space 64
  14.  
  15. # Robot State Message Table
  16. MsgRobotTbl:
  17. .word MsgRS1
  18. .word MsgRS2
  19. .word MsgRS3
  20. .word MsgRS4
  21. .word MsgRS5
  22. MsgFailsDestination: .asciiz "Robot fails to reach Destination\n"
  23.  
  24. MsgRS1: .asciiz "Robot is at a safe place\n"
  25. MsgRS2: .asciiz "Robot falls into Chasm\n"
  26. MsgRS3: .asciiz "Robot falls into the trap\n"
  27. MsgRS4: .asciiz "Robot reaches Destination\n"
  28. MsgRS5: .asciiz "Robot fails to reach Destination\n"
  29. MsgFinal: .asciiz "Robot final location X: "
  30. MsgY: .asciiz " Y: "
  31. MsgCR: .asciiz "\n"
  32. MsgRobotState: .asciiz "Robot State: \n"
  33. MsgFallenChasm: .asciiz "Robot has fallen into a chasm\n"
  34. MsgFallenTrap: .asciiz "Robot has fallen into a trap\n"
  35. MsgReachedDestination: .asciiz "Robot has reached Destination\n"
  36. MsgSafePlace: .asciiz "Robot is at a safe place\n"
  37. MsgFallsChasm: .asciiz "Robot falls into Chasm\n"
  38. MsgFallsTrap: .asciiz "Robot falls into the trap\n"
  39. MsgReachesDestination: .asciiz "Robot reaches Destination\n"
  40.  
  41. .text # CODE SECTION OF ASM FILE
  42.  
  43. #main:
  44. li $v0,30 # Get time
  45. syscall # CMD: Get Time
  46. # $a0 = lower 32-bits, $a1=upper 32-bits
  47.  
  48. # Seed RNG (Random Number Generator)
  49. move $a1,$a0 # get lower 32-bit time as seed
  50. li $a0,0 # Rng#0
  51. syscall # CMD: Seed the RNG
  52.  
  53. # Clear Entire Maze Array
  54.  
  55. la $t0, maze # address of maze
  56. li $t3, 0
  57. li $t1, 144
  58.  
  59. clr: # repeat if not finished yet.
  60. sb $t3, 0($t0)
  61. add $t0, $t0, 1 # address++
  62. add $t1, $t1, -1 # count--
  63. bgtz $t1, clr
  64.  
  65. # _______________
  66. # Setup variables
  67.  
  68. la $t0, maze # base address
  69.  
  70. li $t1,1 # iSAFE:
  71. sb $t1, 0x11($t0) # maze[1][1] = 1;
  72.  
  73. li $t1,2 # iCHASM:
  74. sb $t1, 0x12($t0) # maze[1][2] = 2
  75. sb $t1, 0x24($t0) # maze[2][4] = 2
  76.  
  77. li $t1, 3 #iTRAP:
  78. sb $t1, 0x23($t0) # maze[2][3] = 3
  79. sb $t1, 0x34($t0) # maze[3][4] = 3
  80.  
  81. li $t1, 4 #iDESTINATION:
  82. sb $t1, 0x32($t0) # maze[3][2] = 4;
  83.  
  84. # robot_x = 1
  85. la $t0,robot_x
  86. li $t1,1
  87. sw $t1,0($t0)
  88.  
  89. # robot_y = 2
  90. la $t0,robot_y
  91. li $t1,2
  92. sw $t1,0($t0)
  93.  
  94. # init robot_state = 5
  95. la $t0,robot_state
  96. li $t1,5
  97. sw $t1,0($t0)
  98.  
  99. la $t7,robot_instructions # index
  100. li $t6,64 # Num of loops
  101.  
  102. # _______________
  103. # TOP of BIG Loop
  104. MoveLoop:
  105.  
  106. # Get a Random #
  107. li $a0, 0 # Rng#
  108. li $a1, 4 # rand() %4 {0...3}
  109. li $v0, 42
  110. syscall # Get RNG
  111. # $a0 = {0...3}
  112. add $a0, $a0, 1 # {1...4}
  113.  
  114. # Store Robot instruction
  115. sb $a0,0($t7) # robot_instructions[i] = rnd{ 1...4 }
  116. add $t7, $t7, 1 # increment address
  117.  
  118. add $a0, $a0, -1
  119. bgtz $a0, RJump
  120.  
  121. # ____________
  122. # case 1: MOVE
  123.  
  124. la $t1,robot_m_x
  125. la $t0,robot_x
  126.  
  127. lw $t2,0($t1)
  128. sw $t2,0($t0) # robot_x = robot_m_x
  129.  
  130. la $t1,robot_m_y
  131. la $t0,robot_y
  132. lw $t2,0($t1)
  133. add $t2,$t2,1
  134. sw $t2,0($t0) # robot_y = robot_m_y + 1
  135.  
  136. j Processing # Goto Processing
  137.  
  138.  
  139. RJump:
  140. add $a0, $a0, -1
  141. bgtz $a0, RLeft
  142.  
  143. # ____________
  144. # case 2: Jump
  145.  
  146. la $t1,robot_m_x
  147. la $t0,robot_x
  148.  
  149. lw $t2,0($t1)
  150. sw $t2,0($t0) # robot_x = robot_m_x
  151.  
  152. la $t1,robot_m_y
  153. la $t0,robot_y
  154. lw $t2, 0($t1)
  155. add $t2, $t2, 2
  156. sw $t2, 0($t0) # robot_y = robot_m_y + 2
  157.  
  158. j Processing # Goto Processing
  159.  
  160.  
  161. RLeft:
  162. add $a0, $a0, -1
  163. bgtz $a0, RRight
  164.  
  165. # ____________
  166. # case 3: Left
  167.  
  168. la $t1,robot_m_x
  169. la $t0,robot_x
  170. lw $t2,0($t1)
  171. add $t2, $t2, -1
  172. sw $t2,0($t0) # robot_x = robot_m_x - 1
  173.  
  174.  
  175. j Processing # Goto Processing
  176.  
  177. # _____________
  178. # case 4: Right
  179. RRight:
  180.  
  181. la $t1,robot_m_x
  182. la $t0,robot_x
  183. lw $t2,0($t1)
  184. add $t2, $t2, 1
  185. sw $t2,0($t0) # robot_x = robot_m_x + 1
  186.  
  187. # ______________________________
  188. # Processing new robot positions!
  189.  
  190. Processing:
  191. # System.out.println("Robot final location X: " + robot_x + " Y: " + robot_y);
  192.  
  193. la $a0, MsgFinal
  194. li $v0, 4 # specify Print String service
  195. syscall # print ASCIIz
  196.  
  197. la $t0,robot_x
  198. lw $a0,0($t0)
  199. li $v0, 1
  200. syscall # CMD: print robot_x integer
  201.  
  202. la $a0, MsgY
  203. li $v0, 4 # specify Print String service
  204. syscall # print ASCIIz
  205.  
  206. la $t0,robot_y
  207. lw $a0,0($t0)
  208. li $v0, 1
  209. syscall # CMD: print robot_Y integer
  210.  
  211. la $a0, MsgCR
  212. li $v0, 4 # specify Print String service
  213. syscall # print CRLF
  214.  
  215. # System.out.println ("Robot State: ");
  216. la $t0,robot_x
  217. lw $t0,0($t0) # $t0 = robot_x
  218. la $t5,robot_y
  219. lw $t5,0($t5) # $t5 = robot_y
  220.  
  221. # Using $t1 ... $t4 since they look similar to 1...4
  222. li $t1,1
  223. li $t2,2
  224. li $t3,3
  225. li $t4,4
  226.  
  227. # _____________________________________________________________________________________
  228. # Ref: if (( (robot_x == 1) && (robot_y == 2)) || ( (robot_x == 2) && (robot_y == 4)) )
  229.  
  230. bne $t0,$t1,LineA3 # jump if robot_x <> 1
  231. beq $t5,$t2,LineAOK # jump if robot_y == 2 * Success *
  232.  
  233. LineA3: # || ( (robot_x == 2) && (robot_y == 4)) )
  234. bne $t0,$t2, LineB #jump if robot_x <> 2
  235. bne $t5,$t4, LineB #jump if robot_y <> 4
  236.  
  237. LineAOK: # SUCCESS
  238.  
  239. la $a0, MsgFallenChasm
  240. li $v0, 4 # specify Print String service
  241. syscall # print ASCIIz
  242.  
  243. la $a0, robot_state
  244. sw $t2,0($a0) # robot_state = 2
  245.  
  246. # Process new robot positions
  247.  
  248. j Done
  249.  
  250.  
  251. MoveHop: j MoveLoop # HOP to top of loop
  252.  
  253. # ____________________________________________________________________________________
  254. # Ref: else if(( (robot_x == 2) && (robot_y == 3)) || ((robot_x == 3) && (robot_y == 4)))
  255.  
  256. LineB:
  257. bne $t0,$t2,LineB3 # jump if robot_x <> 2
  258. beq $t5,$t3,LineBOK # jump if robot_y == 3 * Success *
  259.  
  260. LineB3: # || ( (robot_x == 2) && (robot_y == 4)) )
  261.  
  262. bne $t0,$t3, LineC #jump if robot_x <> 3
  263. bne $t5,$t4, LineC #jump if robot_y <> 4
  264.  
  265. LineBOK: # SUCCESS
  266.  
  267. la $a0, MsgFallenTrap
  268. li $vo, 4
  269. syscal #print heading
  270.  
  271. la $a0, robot_state
  272. sw $t3, 0 ($a0) #robot_state=3
  273.  
  274. j Done
  275.  
  276.  
  277. # ___________________________________________
  278. # Ref: if ((robot_x == 3) && (robot_y == 2))
  279. LineC:
  280. bne $t0,$t3, LineD # jump if robot_x <> 3
  281. bne $t5,$t2, LineD # jump if robot_y <> 2
  282.  
  283. # SUCCESS
  284.  
  285. la $a0, MsgReachedDestination
  286. li $vo, 4
  287. syscal #print ASCIIz
  288.  
  289. la $a0, robot_state
  290. sw $t4, 0 ($a0) #robot_state=4
  291.  
  292. j Done
  293.  
  294. # _________________________________________
  295. LineD:
  296.  
  297. la $a0, MsgSafePlace
  298. li $v0, 4 # specify Print String service
  299. syscall # print ASCIIz
  300.  
  301. la $a0, robot_state
  302. sw $t4,0($a0) # robot_state = 1
  303.  
  304. # ___________________
  305. # Print Robot State
  306. Done:
  307. la $a0, robot_state
  308. lw $t0,0($a0) # to is robot_state
  309.  
  310.  
  311.  
  312. ### <--- Insert 4 case robot_state printing!
  313.  
  314.  
  315.  
  316. # ________
  317. # End Loop
  318.  
  319. add $t6, $t6, -1 # count--
  320. bgtz $t1, MoveHop # Hop back to top of big loop
  321.  
  322.  
  323. jr $ra # return
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #145
Aug 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #146
Aug 15th, 2009
#robot_state print

  1. Done:
  2. la $a0, robot_state
  3. lw $t0,0($a0) # to is robot_state
  4.  
  5. la $a0, robot_state
  6. sw $t4,0($a0) # robot_state = 1
  7. syscall
  8.  
  9.  
  10. la $a0, robot_state
  11. sw $t2,0($a0) # robot_state = 2
  12. syscall
  13.  
  14.  
  15. la $a0, robot_state
  16. sw $t3, 0 ($a0) #robot_state=3
  17. syscall
  18.  
  19. la $a0, robot_state
  20. sw $t4, 0 ($a0) #robot_state=4
  21. syscall
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #147
Aug 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 82
Reputation: malugirl4 is an unknown quantity at this point 
Solved Threads: 0
malugirl4 malugirl4 is offline Offline
Junior Poster in Training

Re: Java to Assembly

 
0
  #148
Aug 15th, 2009
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.
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Java to Assembly

 
0
  #149
Aug 15th, 2009
I missed it change those two syscal to syscall

Change $vo to $v0 zero
Reply With Quote Quick reply to this message  
Join Date: Jun 2009
Posts: 830
Reputation: wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all wildgoose is a name known to all 
Solved Threads: 94
wildgoose's Avatar
wildgoose wildgoose is offline Offline
Practically a Posting Shark

Re: Java to Assembly

 
0
  #150
Aug 15th, 2009
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

  1. Done:
  2. la $a0, robot_state
  3. lw $t0,0($a0) # is state 1...5
  4.  
  5. add $t0,$t0,-1 # state is 0...4
  6. sll $t0,$t0,2 # x4 0,4,8,12,16 Address offset
  7.  
  8. # ASCIIz table lookup
  9. la $a0, MsgRobotTbl # table base
  10. add $a0, $a0, $t0
  11. lw $a0,0($a0)
  12.  
  13. li $vo, 4
  14. 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.
Last edited by wildgoose; Aug 15th, 2009 at 4:12 pm.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the Assembly Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC