Error on MOD operator?

Forum for problems or queries regarding the Flowcode application and compiler usage.

Moderators: Benj, Mods

Post Reply
lulu78
Posts: 1
Joined: Sun Nov 30, 2008 12:01 am
Contact:

Error on MOD operator?

Post by lulu78 »

Hello,
That seems too crazy ... I must make a silly mistake! But ...

li is a byte

li = 255 MOD 4 show in variables window 3 ... that's OK

li=0
li = (li-1) MOD 4 show 255 ???

li = (li-1) AND 0b00000011 do the job fine of course.

Some ideas?
Best regards.
Attachments
testMOD.fcf
an flowcode exemple.
(3 KiB) Downloaded 332 times

Sean
Valued Contributor
Valued Contributor
Posts: 548
Joined: Tue Jun 26, 2007 11:23 am
Has thanked: 6 times
Been thanked: 44 times
Contact:

Re: Error on MOD operator?

Post by Sean »

Hello,

The problem seems to be caused when the MOD operator is on the same line as the li - 1 calculation.

Performing the 0 - 1 calculation on an unsigned char variable, which requires special treatment, does not seem to simulate correctly when compounded with the MOD operator - possibly due to the variable types used within the Flowcode simulator.
The code should work correctly when downloaded to a target device.

Placing the MOD operator on a separate line (within the same Flowcode block) seems to solve the simulation problem:

li = li - 1
li = li MOD 4

The same problem does not exist with the int variables because they are signed.

Post Reply