Compiler issue?

General discussion on mikroPascal PRO for PIC.
Post Reply
Author
Message
ermok
Posts: 25
Joined: 19 Sep 2013 11:36

Compiler issue?

#1 Post by ermok » 08 Dec 2018 13:56

Hey,

I have a difficult logic task to analyze bits and seems that compiler can't solve this correctly.

input data is array of 4 bytes:

byte order in array is 0, 1, 2, 3
bit alignment is hi to low; 76543210

11101011 11111100 00110101 00100010 // need to make last init

11101011 11111100 00111111 00101000 // door open
11101011 11111100 00111100 00101011 // no paper

11100011 11111100 00100101 00101010 // paper lo
11100011 11111100 00110101 00111010 // paper hi

11100011 11111100 01110101 01101010 // paper out

PF_Status variable is byte

maybe I want too much of compiler, but next code does not work:

Code: Select all


       PF_Status.B0:= ((TheResult[2].B1 = 1) and (TheResult[3].B1 = 0));// paper door open
       PF_STatus.B2:= ((TheResult[2].B3 = 1) and (TheResult[2].B4 = 1) and (TheResult[3].B0 = 1));// no paper
       PF_Status.B3:= not PF_Status.B2;
       PF_Status.B4:= not PF_Status.B2;
/// some code omitted
       PF_STatus.B3:= ((TheResult[2].B4 = 0) and (TheResult[3].B4 = 0) and (TheResult[3].B0 = 0));// paper lo
       PF_STatus.B4:= ((TheResult[2].B4 = 1) and (TheResult[3].B4 = 1) and (TheResult[3].B0 = 0));// paper hi
       PF_STatus.B5:= ((TheResult[2].B6 = 1) and (TheResult[3].B6 = 1));// paper out

I get wrong results, seemst that compiler creates byte comparsion not bit comparsion.

janni
Posts: 5373
Joined: 18 Feb 2006 13:17
Contact:

Re: Compiler issue?

#2 Post by janni » 09 Dec 2018 00:34

You're assigning boolean values to bits. It should work, but you may also use bit logic (less final code), like

Code: Select all

PF_Status.0:= TheResult[2].1 and not TheResult[3].1;// paper door open
PF_STatus.2:= TheResult[2].3 and TheResult[2].4 and TheResult[3].0; // no paper
I've checked only first two statements of your code and both methods give valid results. Could you point out which statements produce wrong results?

ermok
Posts: 25
Joined: 19 Sep 2013 11:36

Re: Compiler issue?

#3 Post by ermok » 13 Dec 2018 21:19

In the context, only logic values will work. Complex logic with bits renders non-working code. Etc try

Code: Select all

if (function1 = true) and (function2 = true) then
do something
now make function1 return false, it means that function2 never be called, but compiler calls function2.

Now, in my case, array is function argument, code analyzes bits and switches some IOs and prepares next external command, but
logic never worked correctly. I managed to reduce complexity, now code works.

This is feedback to ME team, I hope they can improve compiler and linker. Normally, without thinking how compiler works, I can break compiler almost every day, btw that code will work in Delphi/Lazarus/FPC. But this time, non working direct bit logic was huge suprise.

Post Reply

Return to “mikroPascal PRO for PIC General”