ROBOTC.net forums
http://www.robotc.net/forums/

EV3, V4.30 increment SHORT variables is failing
http://www.robotc.net/forums/viewtopic.php?f=63&t=10560
Page 1 of 1

Author:  OliviliK [ Fri Feb 20, 2015 3:49 pm ]
Post subject:  EV3, V4.30 increment SHORT variables is failing

I am running the RobotC 4.30 on Windows 8.1 with EV3 as target. The ++ operation increments a short variable by 256 instead of 1.

Code:
char   u8   = 100;
short i16   = 200;
long  i32 = 300;
task main() {
   long i;
   char buffer[64];
   clearDebugStream();
   
   GetFWBuild(sizeof(buffer), buffer); 
   writeDebugStream("FWBuild   = ");
   writeDebugStream(buffer);
   
   GetFWVersion(sizeof(buffer), buffer); 
   writeDebugStream("\nFWVersion = ");
   writeDebugStream(buffer);
   
   GetHWVersion(sizeof(buffer), buffer); 
   writeDebugStream("\nHWVersion = ");
   writeDebugStream(buffer);
   
   GetOSBuild(sizeof(buffer), buffer); 
   writeDebugStream("\nOSBuild   = ");
   writeDebugStream(buffer);
   
   GetVersion(sizeof(buffer), buffer); 
   writeDebugStream("\nVersion   = ");
   writeDebugStream(buffer);
   
   writeDebugStream("\n\nIncrements\n");
   
   for (i=0;i<10;i++) {
      writeDebugStream("u8 = %d, i16 = %d, i32 = %d\n",u8++,i16++,i32++);
  }
}


generates the following results in Debug Stream.

Quote:
FWBuild = 1411191539
FWVersion = V1.06X
HWVersion = V0.60
OSBuild = 1411191544
Version = LMS2012 V1.06X(Nov 19 2014 15:39:18)

Increments
u8 = 100, i16 = 200, i32 = 300
u8 = 101, i16 = 456, i32 = 301
u8 = 102, i16 = 712, i32 = 302
u8 = 103, i16 = 968, i32 = 303
u8 = 104, i16 = 1224, i32 = 304
u8 = 105, i16 = 1480, i32 = 305
u8 = 106, i16 = 1736, i32 = 306
u8 = 107, i16 = 1992, i32 = 307
u8 = 108, i16 = 2248, i32 = 308
u8 = 109, i16 = 2504, i32 = 309

Author:  tfriez [ Fri Feb 20, 2015 4:21 pm ]
Post subject:  Re: EV3, V4.30 increment SHORT variables is failing

Yep... looks like there's a bug with globally allocated "short" integers (16-bits). Local "short" doesn't seem to be affected however. Seems to be affecting both the physical robot and our internal emulator, so it might be a compiler or firmware bug.

The immediate workaround is not to use global short variables. We'll work on a solution and have a fix for the next release.

Thanks.

-----

Image

Code:
#pragma debuggerWindows("DebugStream")

char   global_u8   = 100;
short global_i16   = 200;
long  global_i32 = 300;

task main()
{
   char  local_u8   = 10;
   short local_i16  = 20;
   long  local_i32  = 30;   

   short i;
   clearDebugStream();

   writeDebugStream("Increments\n");

   for (i=0;i<10;i++)
   {
      global_u8++;
      global_i16++;
      global_i32++;
      local_u8++;
      local_i16++;
      local_i32++;
      writeDebugStream("Global: u8 = %6d, i16 = %6d, i32 = %6d\n",global_u8,global_i16,global_i32);
      writeDebugStream("Locals: u8 = %6d, i16 = %6d, i32 = %6d\n",local_u8,local_i16,local_i32);
   }
}

Author:  MHTS [ Fri Feb 20, 2015 8:36 pm ]
Post subject:  Re: EV3, V4.30 increment SHORT variables is failing

Could this be little-endian vs big-endian issue? I assume the internal word size of EV3 is 32-bit so a 16-bit short is probably represented as 32-bit internally and it looks like the increment is doing it on the upper 16-bit instead of the lower 16-bit.

Author:  mightor [ Sun Feb 22, 2015 3:12 am ]
Post subject:  Re: EV3, V4.30 increment SHORT variables is failing

Nah, it really was a bug in the firmware and a fix for it has already been put in the source code for the next release. It was an endian-ness-less issue.

= Xander

Author:  OliviliK [ Mon Feb 23, 2015 3:06 pm ]
Post subject:  Re: EV3, V4.30 increment SHORT variables is failing

Nice word endian-ness-less

Page 1 of 1 All times are UTC - 5 hours [ DST ]
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/