Hi Andreas, I am using the Windows version. I compiled the same program under Linux and used the hexfile to program the PIC. The result is the same. I also compared the asm files and they are also the same.
Then I did a test by forcing the Z flag to be TRUE or FALSE before the first function but it made no difference, it all worked OK. So my first analysis of the assembly code was not correct. I am using the latest version of the JAL compiler (v25r8) but for Linux I compiled it for both v25r7 as well as v25r8 but that does not make any difference for this issue. I tested it all on a PIC16F18857. The only way to find the root cause - that I can think of - is if you can reduce the code to where the problem occurs and then send it to me so that I can reproduce it. Thanks. Kind regards, Rob ________________________________ Van: '[email protected]' via jallib <[email protected]> Verzonden: zondag 20 augustus 2023 11:20 Aan: jallib <[email protected]> Onderwerp: Re: [jallib] IF statement fails Hello Rob, thanks for trying this. Your test program is correct. This is (first test only) how it fails in my case. I'm running the LINUX compiler. What is yours? Don't know if this could be a reason for. If you think it makes sense I could try to compile my program under Windows, too to see if there is any differnce. Beside that I think I need to simplyfy my program to hopefully be able to still reproduce it, but simple enough to give you the code. If so what PIC sould I use? Is there a chance to use a simulator to run the code and print the output via serial interface? That we are hardware independend and could ompare our results more easyly. Best Regards, Andreas On Sunday, August 20, 2023 at 10:49:11 AM UTC+2 Rob CJ wrote: Hi Andreas, I made this test program to print messages via the serial port: var byte dummy = 0 var byte i,j,k function test1() return byte is return 0 end function i=test1() if i>0 & i<13 then -- goes here but is wrong print_string(serial, "1: It should NOT come here! ") dummy = dummy + 1 else print_string(serial, "1: This is OK. ") dummy = dummy + 2 end if print_crlf(serial) function test2() return byte is return 0 end function -- but this code works: j=test2() if j<13 & j>0 then dummy = dummy + 3 print_string(serial, "2: It should NOT come here! ") else -- goes here and OK dummy = dummy + 4 print_string(serial, "2: This is OK. ") end if print_crlf(serial) -- if you remove the function, it works, too: k=0 if k>0 & k<13 then dummy = dummy + 5 print_string(serial, "3: It should NOT come here! ") else -- goes here and OK dummy = dummy + 6 print_string(serial, "3: This is OK. ") end if print_crlf(serial) The output on the terminal is as follows: 1: This is OK. 2: This is OK. 3: This is OK. So it does not happen in my case. Can you explain this? Thanks. Kind regards, Rob ________________________________ Van: [email protected] <[email protected]> namens Rob CJ <[email protected]> Verzonden: vrijdag 18 augustus 2023 22:02 Aan: [email protected] <[email protected]> Onderwerp: Re: [jallib] IF statement fails Hi Andreas, Vasile, The reason I think it is an optimization issue is because I had a look at the assembly code when the code reduce option is switched off. The original code that went wrong was this (where the Z flag is not affected): ; 14 i=test1() movlw 0 movwf v_i ; 15 if i>0 & i<13 then movf v_i,w bsf v__bitbucket, 0 ; _btemp1 btfsc v__status, v__z With the code reduce disabled the code is as follows (where the Z flag is affected, because of the subwf instruction): ; 14 i=test1() movlw 0 movwf v_i ; 15 if i>0 & i<13 then movlw 0 subwf v_i,w bcf v__bitbucket, 0 ; _btemp1 btfsc v__status, v__z As said I will test both options on a PIC so see if this indeed solves the problem. If so, I need to have a look at the optimization routine that does this. Kind regards, Rob ________________________________ Van: [email protected] <[email protected]> namens vsurducan <[email protected]> Verzonden: vrijdag 18 augustus 2023 19:12 Aan: [email protected] <[email protected]> Onderwerp: Re: [jallib] IF statement fails :) good idea, no effect... Forcing the operation order does not change anything? If (i<13) & (i>0) then If not, then only some workaround on the if, separe it in two sentences, that usually works. On Fri 18 Aug 2023, 6:12 PM '[email protected]' via jallib, <[email protected]> wrote: I remove d "-no-variable-reuse" from the compiler call to see if there is a different: No it is not, but good idea! Best Regards, Andreas On Friday, August 18, 2023 at 1:45:42 PM UTC+2 vsurducan wrote: Hi Rob, I think it's about disabling reusing variable space and not about expression reduction. On Fri 18 Aug 2023, 9:48 AM Rob CJ, <[email protected]> wrote: Hi Andreas Strange, I will do some testing this weekend. Thanks for the update. Met vriendelijke groet, Rob Jansen ________________________________ From: '[email protected]' via jallib <[email protected]> Sent: Friday, August 18, 2023 8:33:06 AM To: jallib <[email protected]> Subject: Re: [jallib] IF statement fails Hi Rob, I tried that. As a result the code size increased (+200 byte), but the program doesn't work any more, the output on my display stopped working, so it's hard to further debug this. So it's not clear if this helps or not because then other problems come into. Andreas On Thursday, August 17, 2023 at 10:29:51 PM UTC+2 Rob CJ wrote: Hi Andreas, It might be a optimization issues. Can you add the following to your program and test if the problem is gone? pragma opt expr_reduce no It will disable code optimization. Thanks. Kind regards, Rob ________________________________ Van: '[email protected]' via jallib <[email protected]> Verzonden: donderdag 17 augustus 2023 21:42 Aan: jallib <[email protected]> Onderwerp: Re: [jallib] IF statement fails Hi Rob, thanks that you are digging into this problem and maybe found the issue already. I'm a heavy Jal User I would call myself, but this is the first issue I found over the last years :-) On Thursday, August 17, 2023 at 9:31:13 PM UTC+2 Rob CJ wrote: Hi Andreas, I had a quick look at the generated assemble code for a PIC16. In your first code example the code is (I changed 3 times i into i, j and k so I could compile it): ; 10 i=test1() movlw 0 movwf v_i ; 11 if i>0 & i<13 then movf v_i,w bsf v__bitbucket, 0 ; _btemp1 btfsc v__status, v__z In your last code example where you removed the function the code is: clrf v_k ; 35 if k>0 & k<13 then movf v_k,w bsf v__bitbucket, 6 ; _btemp7 btfsc v__status, v__z If I am right - and I hope I am not - the first piece of code does not work because the Z flag (v__z) of the status register (v__status) is never affected by any of these instructions. In the last code example the clrf instruction sets the Z flag. In other words, moving the return value of 0 to v_i is not the same as clearing the value of v_k. So it might be a compiler bug. I wonder why it has not been discovered before. Still need to see if my draft conclusion is correct. Kind regards, Rob ________________________________ Van: '[email protected]' via jallib <[email protected]> Verzonden: donderdag 17 augustus 2023 21:07 Aan: jallib <[email protected]> Onderwerp: Re: [jallib] IF statement fails Hello Rob, PIC is a 18f26K83 compiler called with: ../jalv25r7/compiler/jalv2-x86-64 -no-variable-reuse no other specific setting Thanks, Andreas On Thursday, August 17, 2023 at 9:00:33 PM UTC+2 Rob CJ wrote: Hi, For which PIC did you compile this? 12, 16, 18? Did you use any compiler optimizations? Thanks. Kind regards, Rob ________________________________ Van: '[email protected]' via jallib <[email protected]> Verzonden: woensdag 16 augustus 2023 22:18 Aan: jallib <[email protected]> Onderwerp: [jallib] IF statement fails Hello everyone, I found this code is not working (using jal jalv25r7, but also older versions). Can anyone pls verify: var byte i function test() return byte is return 0 end function i=test() if i>0 & i<13 then -- goes here but is wrong else .. end if but this code works: var byte i function test() return byte is return 0 end function i=test() if i<13 & i>0 then .. else -- goes here and OK end if if you remove the function, it works, too: var byte i i=0 if i>0 & i<13 then .. else -- goes here and OK end if -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/2b197dbf-4628-4acd-b13c-11e3b6ba2228n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/2b197dbf-4628-4acd-b13c-11e3b6ba2228n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/69c9a49a-e83c-4824-a27c-074f25bf0c29n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/69c9a49a-e83c-4824-a27c-074f25bf0c29n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/f2b66222-389b-4f41-8705-41e46aad4528n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/f2b66222-389b-4f41-8705-41e46aad4528n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/c174132e-28a7-4383-9c2d-335a2b025082n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/c174132e-28a7-4383-9c2d-335a2b025082n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB16376699E4BB8A93181105D7E61BA%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM<https://groups.google.com/d/msgid/jallib/GVXP195MB16376699E4BB8A93181105D7E61BA%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/a4d7714c-a139-4928-9611-e43b7425619cn%40googlegroups.com<https://groups.google.com/d/msgid/jallib/a4d7714c-a139-4928-9611-e43b7425619cn%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/CAM%2Bj4qs4wyM2K1hMCWT6ac8yxDNa3yLf8c4Hd-6jpp_rr1412w%40mail.gmail.com<https://groups.google.com/d/msgid/jallib/CAM%2Bj4qs4wyM2K1hMCWT6ac8yxDNa3yLf8c4Hd-6jpp_rr1412w%40mail.gmail.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB16370E4B4A18CF506805D210E61BA%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM<https://groups.google.com/d/msgid/jallib/GVXP195MB16370E4B4A18CF506805D210E61BA%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]<mailto:[email protected]>. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/26dbf27e-8a01-4cae-95f4-0ed25d6fa9e1n%40googlegroups.com<https://groups.google.com/d/msgid/jallib/26dbf27e-8a01-4cae-95f4-0ed25d6fa9e1n%40googlegroups.com?utm_medium=email&utm_source=footer>. -- You received this message because you are subscribed to the Google Groups "jallib" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/jallib/GVXP195MB1637B7AF1F3FCFE4B3FC3A95E619A%40GVXP195MB1637.EURP195.PROD.OUTLOOK.COM.
