Menu

If Sintax (Multiple conditions AND or OR)

Help
JB
2024-03-23
2024-03-25
  • JB

    JB - 2024-03-23

    Hello everyone,
    I have a program with the If syntax , and it' seem when setting for multiple conditions AND an OR it's
    not working.

    Does GCStudio will implement this in any future.

    Tanks to all.

    #option explicit
    #chip tiny10, 8
    
    dir portb.0 in
    dir portb.1 out
    dir portb.2 out
    dir portb.3 in
    
    dim Count as word
    dim Latch as Bit
    
    Latch = 0
    
    do
    
    if portb.0 = 0  then ;off
      Latch = 0
      portb.2 = 0
    end if
    
    ;if portb.0 = 1 then ; **working**
    if portb.0 = 1 and Latch = 0 then ; **not working**
      portb.2 = 1
      Latch = 1
    end if
    
    loop
    
     
  • AVR

    AVR - 2024-03-24

    You have hit the constraints on these little chips.

    Try this, does this work ? This code operates the same and is faster.

    if portb.0 = 1 Then
        If Latch = 0 Then
          portb.2 = 1
          Latch = 1
        end if  
    end if
    

    These chips are very short on resources. So, consider using a used register.bit rather then use RAM. I use ADMUX.0 and ADMUX.1 as my bits, but, I am not using the ADC there maybe other registers that you are not using that your can use.

    So, change to #DEFINE LATCH ADMUX.0. Saves RAM!

    And, you really should install Atmel Toolchain. Using the Atmel Toolchain to verify the ASM generated is the best approach.

    #option explicit
    #chip tiny10, 8
    
    dir portb.0 in
    dir portb.1 out
    dir portb.2 out
    dir portb.3 in
    
    dim Count as word
    #DEFINE LATCH ADMUX.0
    
    LATCH = 0
    
    do
    
    if portb.0 = 0  then ;off
      LATCH = 0
      portb.2 = 0
    end if
    
    ;if portb.0 = 1 then ; **working**
    if portb.0 = 1 then 
        If LATCH = 0 then 
            portb.2 = 1
            LATCH = 1
        end if
    end if
    
    loop
    

    Gives the following using Atmel toolchain. No RAM used.

    Compiling: first-start-sample.gcb
    Program compiled successfully (Compile time: 0.921 seconds)
    
    Summary:
         Compiled:
              Program lines: 21
              Subroutines:  User: 0 ; System: 1 of 455 ; Total: 1
         Chip resource usage:
              Program Memory: 34/512 words (6.64%)
              RAM: 0/32 bytes (0%)
              OSC: 8Mhz
    
    Assembling program using C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR Assembler\Native\2.1.1175\avrassembler\avrasm2.exe
    Program assembled successfully (Assembly time: 0.039 seconds)
    Done
    

    Using GCASM. is 0.013 seconds faster but no validation of the ASM.

    Compiling: first-start-sample.gcb
    Program compiled successfully (Compile time: 0.906 seconds)
    
    Summary:
         Compiled:
              Program lines: 21
              Subroutines:  User: 0 ; System: 1 of 455 ; Total: 1
         Chip resource usage:
              Program Memory: 34/512 words (6.64%)
              RAM: 0/32 bytes (0%)
              OSC: 8Mhz
    
    Assembling program using GCASM
    Program assembled successfully (Assembly time: 0.023 seconds)
    Done
    

    Your original program... gives these errors.

    Compiling: first-start-sample.gcb
    Program compiled successfully (Compile time: 0.921 seconds)
    
    Summary:
         Compiled:
              Program lines: 19
              Subroutines:  User: 0 ; System: 1 of 455 ; Total: 1
         Chip resource usage:
              Program Memory: 49/512 words (9.57%)
              RAM: 1/32 bytes (3.12%)
              OSC: 8Mhz
    
    Assembling program using C:\Program Files (x86)\Atmel\Atmel Toolchain\AVR Assembler\Native\2.1.1175\avrassembler\avrasm2.exe
    C:\GCstudio\gcbasic\demos\first-start-sample.asm(119): error: Undefined symbol: F
    C:\GCstudio\gcbasic\demos\first-start-sample.asm(119): error: Wrong number of operands
    C:\GCstudio\gcbasic\demos\first-start-sample.asm(124): error: Undefined symbol: F
    C:\GCstudio\gcbasic\demos\first-start-sample.asm(124): error: Wrong number of operands
    
    Assembly failed, 4 errors, 0 warnings
    Program assembled successfully (Assembly time: 0.054 seconds)
    Done
    

    Nice little chip. A pain to use.

     
  • Anobium

    Anobium - 2024-03-24

    THIS IS AN EDITED POST. MY INITIAL POST WAS SO WRONG.

    @AVR - very good. Good advice. Use the workaround.

    We are looking at two issues here. Both, latent issues and not reported or noticed. You get the same error across all AVRs when you have a two BIT test statement.

    1. The error in the ASM and therefore the fail in AVR2ASM. I have just looked at the Change log for the compiler. Hugh added the BIT test code un Oct 2018 change[805] and he made an error in the ASM. I have correct that error. And, now the AVR2ASM compiles correctly.

    2. The error with the logic is more complex. The workaround resolves, but, it took me a while to figure out. The compiler is doing exactly as asked.

     

    Last edit: Anobium 2024-03-24
  • Anobium

    Anobium - 2024-03-24

    THIS IS A NEW POST. MY INITIAL POST WAS SO WRONG. I have edited the previous post.

    @AVR - very good. Good advice. Use the workaround.

     
  • JB

    JB - 2024-03-24

    Many thanks , AVR, Anobium

     

    Last edit: JB 2024-03-24
  • Anobium

    Anobium - 2024-03-25

    I think I have resolved to make in work with the Tiny10.

    Ping me a Personal Message. I will let you have a new compiler. Build #1377


    The root cause of the issue was incorrect generation of ASM and a typo deep inside the compiler.

    1. The typo was relatively simple to fix. I found the type in a few minutes. The typo was introduced in Oct 2018 by Hugh. But, this was not picked up by GCASM. Using AVR2ASM did pick this up.
    2. The generation of the correct ASM took all day. To resolve.
      These comments are only for AVR/LGT ( not applicable to PIC).

    A single BIT conditional test worked. The implementation of a single bit test is relatively simple, test the bit and jump.
    Multiple BIT conditional tests is vey different and handled by a different part of the compiler. The compiler CLeaRed a register and then tested the first bit state, cached the bit, tested the second bit and then 'and' the two together for result testing. However, this was wrong ( this analysis took many hours as I totally trust Hugh's coding ). The compiled should SET the register when testing then when the 'and' for result testing.

    This is fixed in build #1377.

    Here is a video of the testing:

    The attachment is the document I use to enable me to understand the issue.

    Hopefully, resolved.

    Enjoy

     
    • JB

      JB - 2024-03-25

      Hello,
      this is a very good news saw the OSHONSOFT IDE video very impressive demonstration.
      I'm not at all on this level yet.

      is this will work only for Bit or other like Byte, Word
      let me know how to get #1377, I'll do some testing with tiny10 and let you know.
      Thanks again for your great work.

       

      Last edit: JB 2024-03-25
      • Anobium

        Anobium - 2024-03-25

        The bit test is only for the BITS, or BITS of a BYTE or WORD ( like BYTE_VAR.0 ). So, this fix is specific to multiple BIT test conditions.

        To get the release. GCBASIC.EXE and MESSAGE.DAT from here - replace your local one version. https://gcbasic.com/reps/goldbuild/masterbuild/GCB%40Syn/GreatCowBASIC/ We are mid the floats testing and download loading directly will work for you.

         
  • JB

    JB - 2024-03-25

    Many thanks,

     
  • JB

    JB - 2024-03-25

    Maybe I'm doing something wrong, when I click on the files I get error 404.

     
    • Anobium

      Anobium - 2024-03-25

      Right hand context menu, 'save link as ... " then save to local download.

       
  • JB

    JB - 2024-03-25

    I did right click on the file, when trying to save
    I've got "File wasn't available on site"

     
    • Anobium

      Anobium - 2024-03-25

      Not sure of issue. It is not really meant to be downloaded from... it was a quick way for you.

      Try this. You will have to accept all the warning etc. when you download

      http://gcbasic.sourceforge.net/newfiles/1377.zip?latest=1

       
  • JB

    JB - 2024-03-25

    Work !
    Compiler Version: 2024.3.24 (Windows 64 bit) : Build 1377) Program Memory: 126/1024 bytes (12.3%) RAM: 1/32 bytes (3.12%) OSC: 8Mhz Chip: TINY10

     
  • JB

    JB - 2024-03-25

    Work !
    Compiler Version: 2024.3.24 (Windows 64 bit) : Build 1377) Program Memory: 126/1024 bytes (12.3%) RAM: 1/32 bytes (3.12%) OSC: 8Mhz Chip: TINY10

     
    • Anobium

      Anobium - 2024-03-25

      Does it work as a compiler? or, does the program logic work? or, both?

       
  • JB

    JB - 2024-03-25

    Both the compiler and the logic circuit.

     
    • Anobium

      Anobium - 2024-03-25

      Great news.

       
  • JB

    JB - 2024-03-25

    Also you fix my sloppy code for DIR ( dir portb.1,2,3 out)
    Error: Invalid DIRection command. Command cannot contain ',' 1

    Thanks again

     
    • Anobium

      Anobium - 2024-03-25

      I thought about leaving the ',' for a millisecond. But, it would only lead to confusion.

      Many years ago when Hugh initially developed GCBASIC there was a UI that would control all aspects of the program. It also applied many rules. Those rules are what I constantly embed with Syntax and other Error handlers.

       
  • JB

    JB - 2024-03-25

    Good work, really appreciate

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.