<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:wikidot="http://www.wikidot.com/rss-namespace">

	<channel>
		<title>Error in Aseba Programming Language?</title>
		<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language</link>
		<description>Posts in the discussion thread &quot;Error in Aseba Programming Language?&quot;</description>
				<copyright></copyright>
		<lastBuildDate>Tue, 14 Jul 2026 22:21:44 +0000</lastBuildDate>
		
					<item>
				<guid>http://aseba.wikidot.com/forum/t-605140#post-1686398</guid>
				<title>Re: Error in Aseba Programming Language?</title>
				<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language#post-1686398</link>
				<description></description>
				<pubDate>Tue, 15 Jan 2013 18:28:20 +0000</pubDate>
				<wikidot:authorName>Michael Bieri</wikidot:authorName>				<wikidot:authorUserId>1477842</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Did not have access to a Thymio for a few weeks, but I could test it today: Yes, this was the problems!</p> <p>sptr = sptr does not make any sense. I think it can not explain the whole strange behavior, but it could confuse the compiler or something.</p> <p>So, finally, thanks for the help!</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-605140#post-1668319</guid>
				<title>Re: Error in Aseba Programming Language?</title>
				<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language#post-1668319</link>
				<description></description>
				<pubDate>Sun, 23 Dec 2012 14:31:06 +0000</pubDate>
				<wikidot:authorName>Michael Bieri</wikidot:authorName>				<wikidot:authorUserId>1477842</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Thanks for your answer! I will check it in the next days.</p> <p>The issue with the sptr seems to be a possible solution.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-605140#post-1665122</guid>
				<title>Re: Error in Aseba Programming Language?</title>
				<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language#post-1665122</link>
				<description></description>
				<pubDate>Fri, 21 Dec 2012 08:16:50 +0000</pubDate>
				<wikidot:authorName>vaussard</wikidot:authorName>				<wikidot:authorUserId>872375</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>To confirm, I disassembled the generated code. Looking at both the syntax tree, and the bytecode, I don't see problems related to the compiler. The problem probably comes from a memory corruption. Please, consider my first post.</p> <p>Here are the syntax tree and the bytecode for the above-mentioned part of the code. For the bytecode, I interleaved the Aseba code, to make it easier to read.</p> <div class="code"> <pre><code>Block Assign Store: addr 192 BinaryArithmetic: + Load: addr 192 Immediate: 1 Block Assign ArrayWrite: addr 171 size 9 Load: addr 169 Load: addr 192 Folded If: == Load: addr 191 Immediate: 1 Block Block Assign Store: addr 190 UnaryArithmetic: unary - Load: addr 190 Block Assign Store: addr 169 BinaryArithmetic: + Load: addr 169 Immediate: 1 Block Assign ArrayWrite: addr 171 size 9 Load: addr 169 Immediate: 0 Block Assign ArrayWrite: addr 180 size 9 Load: addr 169 Immediate: 0 sub play_recursive: (max stack 4) [...] # rcnt = rcnt + 1 535 (170) : LOAD 192 536 (170) : SMALL_IMMEDIATE 1 537 (170) : BINARY_ARITHMETIC + 538 (170) : STORE 192 # stack_rcnt[sptr] = rcnt 539 (171) : LOAD 192 540 (171) : LOAD 169 541 (171) : STORE_INDIRECT in array at 171 of size 9 # if (down == 1) then 543 (173) : LOAD 191 544 (173) : SMALL_IMMEDIATE 1 545 (173) : CONDITIONAL_BRANCH ==, skip 17 if false # player = -player 547 (174) : LOAD 190 548 (174) : UNARY_ARITHMETIC unary - 549 (174) : STORE 190 # sptr = sptr + 1 550 (175) : LOAD 169 551 (175) : SMALL_IMMEDIATE 1 552 (175) : BINARY_ARITHMETIC + 553 (175) : STORE 169 # stack_rcnt[sptr] = 0 554 (176) : SMALL_IMMEDIATE 0 555 (176) : LOAD 169 556 (176) : STORE_INDIRECT in array at 171 of size 9 # stack_set[sptr] = 0 558 (177) : SMALL_IMMEDIATE 0 559 (177) : LOAD 169 560 (177) : STORE_INDIRECT in array at 180 of size 9</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-605140#post-1662952</guid>
				<title>Re: Error in Aseba Programming Language?</title>
				<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language#post-1662952</link>
				<description></description>
				<pubDate>Thu, 20 Dec 2012 20:34:57 +0000</pubDate>
				<wikidot:authorName>vaussard</wikidot:authorName>				<wikidot:authorUserId>872375</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>In the code mentioned by you, there should not be such optimization (at least not written by me ;-). A dump of the generated bytecode would clarify the situation. I don't have a Thymio at hand, but will have a look tomorrow. BTW, it would be easier to reproduce if you can post the aesl script, it will include constants and so on.</p> <p>However, rapidly looking at your code, in the event timer0, I saw the following lines:</p> <div class="code"> <pre><code> sptr0 = move_cnt * 2 sptr = sptr</code></pre></div> <p>Is the assignment of <tt>sptr</tt> to <tt>sptr</tt> right? It looks suspicious. By searching through your code, <tt>sptr</tt> is never reset to a know value, it is only incremented or decremented.</p> 
				 	]]>
				</content:encoded>							</item>
					<item>
				<guid>http://aseba.wikidot.com/forum/t-605140#post-1659882</guid>
				<title>Error in Aseba Programming Language?</title>
				<link>http://aseba.wikidot.com/forum/t-605140/error-in-aseba-programming-language#post-1659882</link>
				<description></description>
				<pubDate>Wed, 19 Dec 2012 17:45:05 +0000</pubDate>
				<wikidot:authorName>Michael Bieri</wikidot:authorName>				<wikidot:authorUserId>1477842</wikidot:authorUserId>				<content:encoded>
					<![CDATA[
						 <p>Hello</p> <p>My Thmyio II is nearly full (91%) and now, a strange behavior occurs. Consider the following lines:</p> <div class="code"> <pre><code>rcnt = rcnt + 1 stack_rcnt[sptr] = rcnt if(down == 1) then player = -player sptr = sptr + 1 stack_rcnt[sptr] = 0 stack_set[sptr] = 0 end</code></pre></div> <p>I step through the code with the debugger. When I'm at the if-statement I expect that the next step will be either player = - player, or it will skip the whole block. BUT after the if-statement, it directly jumps to stack_set[sptr] = 0, which is not possible in any case.</p> <p>In other programming languages, a similiar behavior is observed with highly optimized code sometimes, when assembly lines do no longer clearly correspond to a source code line. But in this case, nevertheless, sptr = sptr + 1 and player = - player after the block. But this is not the case.</p> <p>So what's wrong here?</p> <p>You find the full code below, the above snippet is around line 180.</p> <div class="code"> <pre><code>var STATE_GAME_WAIT = 0 var STATE_GAME_SCAN = 1 var STATE_GAME_PUT = 2 var STATE_GAME_WAIT_FIRST = 3 var STATE_GAME = STATE_GAME_WAIT_FIRST var move_cnt = 0 var playground[9] = [0, 0, 0, 0, 0, 0, 0, 0, 0] var last_playground[9] var scanning = 0 var put_target = 8 var last_move = 0 var path_cnt = 0 var path_len = 0 var path[PATH_MAX_LEN] = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0] var STATE_NAVI_DRIVE = 1 var STATE_NAVI_JUNCTION_CROSS = 2 var STATE_NAVI_BACK = 3 var STATE_NAVI_BACK_JUNCTION_CROSS = 4 var STATE_NAVI_JUNCTION_cross_offset = 100 var STATE_NAVI_JUNCTION = 5 var STATE_NAVI_JUNCTION_turn_offset = 400 var STATE_NAVI_JUNCTION_turnmin = 250 var STATE_NAVI_TURN_LEFT = 6 var STATE_NAVI_TURN_RIGHT = 7 var STATE_NAVI = STATE_NAVI_DRIVE var turncnt = 0 var cnt = 0 var LINE_LEFT = 0 var LINE_RIGHT = 0 var SPEED_NORMAL = 200 var SPEED_LINE_ADJUST = 0 var SPEED_TURN = 100 var speed_left = 0 var speed_right = 0 var i = 0 var j = 0 var k = 0 var score[9] = [0, 0, 0, 0, 0, 0, 0, 0, 0] var sptr = 0 var sptr0 = 0 var stack_rcnt[9] = [0, 0, 0, 0, 0, 0, 0, 0, 0] var stack_set[9] = [0, 0, 0, 0, 0, 0, 0, 0, 0] var win = 0 var player = 0 var down = 0 var rcnt = 0 var set = 0 var stop = 0 var finished = 0 var maxscore = 0 timer.period[0] = 2000 #2 sub set_motor motor.left.target = speed_left motor.right.target = speed_right sub scan if scanning == 1 then if prox.horizontal[4] &gt; 0 then playground[path_cnt] = 1 end end sub compute_last_move for i in 0:8 do if not(playground[i] == last_playground[i]) then last_move = i end end last_playground = playground sub check_win win = 0 if (playground[0] == player)and(playground[1] == player)and(playground[2] == player) then win = 1 end if (playground[7] == player)and(playground[3] == player)and(playground[8] == player) then win = 1 end if (playground[4] == player)and(playground[5] == player)and(playground[6] == player) then win = 1 end if (playground[0] == player)and(playground[7] == player)and(playground[6] == player) then win = 1 end if (playground[1] == player)and(playground[8] == player)and(playground[5] == player) then win = 1 end if (playground[2] == player)and(playground[3] == player)and(playground[4] == player) then win = 1 end if (playground[0] == player)and(playground[8] == player)and(playground[4] == player) then win = 1 end if (playground[2] == player)and(playground[8] == player)and(playground[6] == player) then win = 1 end sub play_recursive for i in 0:8 do score[i] = 0 end while(stop == 0) do down = 0 finished = 0 rcnt = stack_rcnt[sptr] set = stack_set[sptr] if(rcnt &lt; 9) then if(set == 1) then playground[rcnt - 1] = 0 end if(playground[rcnt] == 0) then stack_set[sptr] = 1 playground[rcnt] = player callsub check_win if(win == 1) then score[stack_rcnt[sptr0] - 1] = score[stack_rcnt[sptr0] - 1] + player finished = 0 end player = -player callsub check_win if(win == 1) then score[stack_rcnt[sptr0] - 1] = score[stack_rcnt[sptr0] - 1] + player finished = 0 end player = -player if((sptr &lt; 8) and (finished == 0)) then down = 1 end else stack_set[sptr] = 0 end rcnt = rcnt + 1 stack_rcnt[sptr] = rcnt if(down == 1) then player = -player sptr = sptr + 1 stack_rcnt[sptr] = 0 stack_set[sptr] = 0 end else sptr -- player = -player end if(sptr &lt; sptr0) then stop = 1 end end maxscore = 32000 for i in 0:8 do if score[i] &lt; maxscore then put_target = i maxscore = score[i] end end sub play callsub compute_last_move if move_cnt == 0 then put_target = 8 move_cnt = 1 elseif move_cnt == 1 then if (last_move == 0) or (last_move == 1) then put_target = 4 elseif (last_move == 2) or (last_move == 3) then put_target = 6 elseif (last_move == 4) or (last_move == 5) then put_target = 0 elseif (last_move == 6) or (last_move == 7) then put_target = 2 end move_cnt = 2 elseif move_cnt &gt;= 2 then player = - 1 sptr = move_cnt * 2 stop = 0 callsub play_recursive move_cnt = move_cnt + 1 end playground[put_target] = -1 callsub compute_last_move sub fsm_game if STATE_GAME == STATE_GAME_WAIT_FIRST then if prox.horizontal[2] &gt; 0 then move_cnt = 0 scanning = 0 path_cnt = 0 playground[0:8] = [0, 0, 0, 0, 0, 0, 0, 0, 0] STATE_GAME = STATE_GAME_SCAN end elseif STATE_GAME == STATE_GAME_WAIT then if prox.horizontal[2] &gt; 0 then scanning = 1 path[0:7] = [-1, 0, -1, 0, -1, 0, -1, 0] path_len = 8 path_cnt = 0 STATE_GAME = STATE_GAME_SCAN end elseif STATE_GAME == STATE_GAME_SCAN then scanning = 0 path_cnt = 0 callsub play if put_target == 0 then path[0:11] = [0, 1, 3, 1, 1, 0, -1, 0, -1, 0, -1, 0] path_len = 12 elseif put_target == 1 then path[0:9] = [-1, 1, 3, -1, -1, 0, -1, 0, -1, 0] path_len = 10 elseif put_target == 2 then path[0:11] = [-1, 0, 1, -1, 3, -1, 0, 0, -1, 0, -1, 0] path_len = 12 elseif put_target == 3 then path[0:9] = [-1, 0, -1, 1, 3, -1, -1, 0, -1, 0] path_len = 10 elseif put_target == 4 then path[0:11] = [-1, 0, -1, 0, 0, 1, 3, 1, 1, 0, -1, 0] path_len = 12 elseif put_target == 5 then path[0:9] = [-1, 0, -1, 0, -1, 1, 3, -1, -1, 0] path_len = 10 elseif put_target == 6 then path[0:11] = [-1, 0, -1, 0, -1, 0, 1, -1, 3, -1, 0, 0] path_len = 12 elseif put_target == 7 then path[0:11] = [1, 1, 3, 1, 0, 0, -1, 0, -1, 0, -1, 0] path_len = 12 elseif put_target == 8 then path[0:9] = [-1, -1, 3, 1, -1, 0, -1, 0, -1, 0] path_len = 10 end STATE_GAME = STATE_GAME_PUT elseif STATE_GAME == STATE_GAME_PUT then STATE_GAME = STATE_GAME_WAIT end sub fsm_navi if STATE_NAVI == STATE_NAVI_DRIVE then if path_cnt == path_len then speed_right = 0 speed_left = 0 callsub set_motor callsub fsm_game else callsub scan if (LINE_LEFT == 1) and (LINE_RIGHT == 1) then speed_right = SPEED_NORMAL speed_left = SPEED_NORMAL callsub set_motor cnt = STATE_NAVI_JUNCTION_cross_offset STATE_NAVI = STATE_NAVI_JUNCTION_CROSS elseif (LINE_LEFT == 1) then speed_right = SPEED_NORMAL speed_left = SPEED_LINE_ADJUST callsub set_motor elseif (LINE_RIGHT == 1) then speed_right = SPEED_LINE_ADJUST speed_left = SPEED_NORMAL callsub set_motor else speed_right = SPEED_NORMAL + (prox.ground.delta[1] - prox.ground.delta[0]) speed_left = SPEED_NORMAL + (prox.ground.delta[0] - prox.ground.delta[1]) callsub set_motor end end elseif STATE_NAVI == STATE_NAVI_JUNCTION_CROSS then speed_right = SPEED_NORMAL speed_left = SPEED_NORMAL callsub set_motor callsub scan cnt = cnt - 1 if path[path_cnt] == 3 then cnt = 150 STATE_NAVI = STATE_NAVI_BACK elseif cnt == 0 then STATE_NAVI = STATE_NAVI_JUNCTION if path[path_cnt] == 0 then cnt = 1 else cnt = STATE_NAVI_JUNCTION_turn_offset end end elseif STATE_NAVI == STATE_NAVI_BACK then speed_right = -SPEED_NORMAL speed_left = -SPEED_NORMAL callsub set_motor if cnt &lt; 0 then if (LINE_LEFT == 1) and (LINE_RIGHT == 1) then STATE_NAVI = STATE_NAVI_JUNCTION_CROSS cnt = STATE_NAVI_JUNCTION_cross_offset path_cnt = path_cnt + 1 end end cnt = cnt - 1 elseif STATE_NAVI == STATE_NAVI_JUNCTION then cnt = cnt - 1 callsub scan if cnt &lt; 0 then if path[path_cnt] == 0 then STATE_NAVI = STATE_NAVI_DRIVE elseif path[path_cnt] == -1 then STATE_NAVI = STATE_NAVI_TURN_LEFT turncnt = 1 cnt = STATE_NAVI_JUNCTION_turnmin elseif path[path_cnt] == 1 then STATE_NAVI = STATE_NAVI_TURN_RIGHT turncnt = 1 cnt = STATE_NAVI_JUNCTION_turnmin elseif path[path_cnt] == -2 then STATE_NAVI = STATE_NAVI_TURN_LEFT turncnt = 2 cnt = STATE_NAVI_JUNCTION_turnmin elseif path[path_cnt] == 2 then STATE_NAVI = STATE_NAVI_TURN_RIGHT turncnt = 2 cnt = STATE_NAVI_JUNCTION_turnmin end if path_cnt == PATH_MAX_LEN - 1 then path_cnt = 0 else path_cnt = path_cnt + 1 end end elseif STATE_NAVI == STATE_NAVI_TURN_RIGHT then speed_right = - SPEED_TURN speed_left = SPEED_TURN callsub set_motor if cnt &gt; 0 then cnt = cnt - 1 elseif cnt == 0 then if LINE_RIGHT == 1 then cnt = - 1 end elseif cnt == - 1 then if LINE_LEFT == 1 then if turncnt == 1 then STATE_NAVI = STATE_NAVI_DRIVE else turncnt = turncnt - 1 cnt = STATE_NAVI_JUNCTION_turnmin end end end elseif STATE_NAVI == STATE_NAVI_TURN_LEFT then speed_right = SPEED_TURN speed_left = - SPEED_TURN callsub set_motor if cnt &gt; 0 then cnt = cnt - 1 elseif cnt == 0 then if LINE_LEFT == 1 then cnt = - 1 end elseif cnt == - 1 then if LINE_RIGHT == 1 then if turncnt == 1 then STATE_NAVI = STATE_NAVI_DRIVE else turncnt = turncnt - 1 cnt = STATE_NAVI_JUNCTION_turnmin end end end end onevent timer0 timer.period[0] = 0 move_cnt = 2 playground = [1, 1, 0, 0, 0, 0, -1, 0, -1] player = - 1 sptr0 = move_cnt * 2 sptr = sptr stop = 0 callsub play_recursive stop = 1 sub bla if (prox.ground.delta[0] &lt; 50) or (prox.ground.delta[1] &lt; 50) then STATE_GAME = STATE_GAME_WAIT_FIRST callsub fsm_game else if (prox.ground.delta[0] &lt; 500) then LINE_LEFT = 1 else LINE_LEFT = 0 end if (prox.ground.delta[1] &lt; 500) then LINE_RIGHT = 1 else LINE_RIGHT = 0 end end callsub fsm_navi</code></pre></div> 
				 	]]>
				</content:encoded>							</item>
				</channel>
</rss>