Simulation - extension of byte to 32 bit.

Moderator: Benj

Post Reply
mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Simulation - extension of byte to 32 bit.

Post by mnf »

A bug in the simulation engine.

The engine seems to use a 'longer than 8 bit' value in calculations and 8 bit values don't seem to be extended correctly..
sim_bug.fcfx
(7.77 KiB) Downloaded 129 times
Demonstrates this.

This may be by design - byte is described as 0..255 so my treating it as as signed 8 bit number might be wrong here?

Martin

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: Simulation - extension of byte to 32 bit.

Post by Benj »

Hi Martin,

Thanks that;s an interesting one. Does this work as expected on hardware?

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Simulation - extension of byte to 32 bit.

Post by mnf »

I'll try it - I assumed it would since it would do an 8 bit comparison for a byte,,, But it might not?

Martin

mnf
Valued Contributor
Valued Contributor
Posts: 1189
Joined: Wed May 31, 2017 11:57 am
Has thanked: 70 times
Been thanked: 439 times
Contact:

Re: Simulation - extension of byte to 32 bit.

Post by mnf »

No - doesn't work on hardware (indeed the code is optimised out to for the =-1 side of the conditonal)

I see it is defined as an unsigned char (MX_UINT8) - so I suppose this is the correct behaviour (as it should = 255 here)

Strangely if I define a variable x as (initial value) -1 then

Code: Select all

MX_UINT8 FCL_X = (0xffffffff);
is generated (some spare fs!)

I see there is a MX_SINT8 defined in the header files - but a signed byte variable isn't offered as a choice in the 'create a variable'

I think my 'cheating' and using -1 as a shorthand for 255 has led me astray here - the compiler is doing the correct thing....

Martin

Post Reply