Menu

Error in generated AVR ASM for maths calc

2022-08-13
2022-11-28
1 2 > >> (Page 1 of 2)
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    (Unfortunately) hello again

    I attach a program, which is a (tabletop) project running on STK200, to add a speaker dependent voice control to my railroad layout, using Fortebit's EasyVR3 (the expression "Easy" is not really adapted, since the system is a "gaseous plant", look for the many configuration commands and for the handshake in lines 100 to 104). The result should be displayed on the Leds of the STK200. Now the issue : it occurs in line 131, which in fact behaves like : Travail = 17 +32(asterisk)Mode_passage_interactif ; it works only if I split it into 2 lines :
    Travail = 17 + 2(asterisk)Numero_train_interactif
    Travail = Travail + 32(asterisk)Mode_passage_interactif.
    The same error occurs if I add parentheses around the multiplications, and with Mega162 too ..

    Panic !

    (64bit version of GC Basic, Build1132 by "patching")

     

    Last edit: Bertrand BAROTH 2022-08-13
  • Anobium

    Anobium - 2022-08-13

    I can look into it. But, use two lines for now.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    I knew such limitations in Bascom, and for concatenating strings in GCBasic, but not for calculation formulas in GCB ...

     
  • Anobium

    Anobium - 2022-08-13

    I have created this program.

    #chip 16f88
    #Option explicit
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    
    Dim Numero_train_interactif as Byte
    Dim Mode_passage_interactif as Byte
    Dim Travail as Byte
    
    
    For Mode_passage_interactif = 1 to 3
      For Numero_train_interactif = 0 to 3
        Travail=17+2*Numero_train_interactif+32*Mode_passage_interactif
        HserPrintByteCRLF Travail
        wait 500 ms
      Next
    Next
    

    On the 16F88 I get the same results as I do in Excel. I have modelled in Microsoft Excel.

    49-51-53-55
    81-83-85-87
    113-115-117-119
    

    So, there is a problem not in the calculation but in ASM generated from the calcs.

    Please try this program on your chip. I need the results and the ASM.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Since I have no RS232 interface on my computer, I modified the program to display the result on the Leds. And Leds 1 to 3 were always off, this means that 2(asterisk)Numero_train_inetractif was discarded ...

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Since I have no RS232 interface on my computer, I modified the program to display the result on the Leds. And Leds 1 to 3 were always off, this means that 2(asterisk)Numero_train_interactif was discarded ...

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Unable to edit a post, text disappears, malfunction of the forum.

     
  • Anobium

    Anobium - 2022-08-13

    Thank you.

    The root cause of the issue is the use of the MUL ( Multiplier ) of the 32 - this impacts the registers previously used for multiple of 2 calc.

    So, knowing this... Travail=17+32*Mode_passage_interactif+2*Numero_train_interactif works. As This does the Multiplier* 32 first, adds 17, add the other calc.

    I need to think on how to resolve this for the future.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Do You know the movie "Jinxed" (the story with the coin in the fountain ...), where Mr. Murphy works as a beta tester, assuming that according to Murphy's law, if anything could go wrong with a system it would happen to him ? I think finally that my other name is Murphy, too !

    :)

     
  • Anobium

    Anobium - 2022-08-13

    This is resolved in the new compiler ( build 1147 or greater).

    If the calculation using the hardware multiplier is at risk of overwriting registers then it will use the software multiplier. This is a tad slower but very robust.

    Meanwhile... these work

    Travail=17+2*Numero_train_interactif+fnLSL(Mode_passage_interactif,5)

    and

    Travail=17+32*Mode_passage_interactif+2*Numero_train_interactif


    Also, in the new compiler you can turn off the hardware multiplier yourself by undefining the constant.

    #UNDEFINE HardwareMult

    This will ensure the software routines are used.

    Evan

     

    Last edit: Anobium 2022-08-13
  • Anobium

    Anobium - 2022-08-13

    My reference code. This will ONLY work on version 1.xx.xx or build 1147 or greater.

    /*
    Test code for compiler
    */
    
    #CHIP MEGA328P, 16
    #OPTION EXPLICIT
    
    #DEFINE USART_BAUD_RATE 9600
    #DEFINE USART_TX_BLOCKING
    #DEFINE USART_DELAY OFF
    
    'Determine if AVR HardwareMult is enabled
            #IFDEF HardwareMult
                'Requires v1.xx.xx of the compiler
                #UNDEFINE HardwareMult
            #ENDIF
    
            'add, just check it has gone!
            #SCRIPT
                IF DEF(HARDWAREMULT) THEN
                    WARNING "HARDWAREMULT EXISTS"
                END IF
            #ENDSCRIPT
    
            Dim Numero_train_interactif as Byte
            Dim Mode_passage_interactif as Byte
            Dim Travail as Byte
    
            Wait 2 s
    
    #DEFINE OneLineCalc
    
        #IFDEF OneLineCalc
            HserPrint "Short Calc"
            HserPrintCRLF
        #ELSE
            HserPrint "Two Line Calc"
            HserPrintCRLF
        #ENDIF
    
        Do
            For Mode_passage_interactif = 1 to 3
                For Numero_train_interactif = 0 to 3
                    #IFDEF OneLineCalc
                        // Original method
                        Travail=17+2*Numero_train_interactif+32*Mode_passage_interactif
    
                        // other methods
                        // Travail=17+2*Numero_train_interactif+fnLSL(Mode_passage_interactif,5)
                        // Travail=32*Mode_passage_interactif+17+2*Numero_train_interactif
                    #ELSE
                        Travail = 17 + 2*Numero_train_interactif
                        Travail = Travail + 32*Mode_passage_interactif
                    #ENDIF
                    HserPrintByteCRLF Travail
                Next
            Next
            HserPrintCRLF 2
            wait 2 s
        Loop
    
     

    Last edit: Anobium 2022-08-13
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Where can I get a patch to upgrade at least to 1147 without using studio (which doesn't work on my Windows version) ?

     
    • Anobium

      Anobium - 2022-08-13

      It is a few days away.

      Use the other methods for now but if you want to make sure the software maths is used.. open the CHIP DAT file and change HardwareMult=y to HardwareMult=n

      But, it will only come in the GCStudio wrapper.
      You can install GCStudio and then copy the install out.

      But, get Angel to get it working for you OS.

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Don't worry too much about my issue with Studio : I tested it, it didn't install, this is not the world's end ... About calculations : I signaled this for those people who NEED to make calculations ; in fact normally I would have performed these operations with a combination of shiftings and "or"s ; it was my first multiplication since 2018, and probavly the last one, too ! In my application program for the layout I need only bit operations, maskings, tests, additions and substractions, only operations very close to their equivalents in machine language.

     
    • Anobium

      Anobium - 2022-08-13

      OK re Studio

      I would still disable HardwareMult until you get the new compiler.

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Don't worry too much about my issue with Studio : I tested it, it didn't install, this is not the world's end ... About calculations : I signaled this for those people who NEED to make calculations ; in fact normally I would have performed these operations with a combination of shiftings and "or"s ; it was my first multiplication since 2018, and probably the last one, too ! In my application program for the layout I need only bit operations, maskings, tests, additions and substractions, only operations very close to their equivalents in machine language.

     
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    Still impossible to edit .. I had a misspelling (probavly) in my first post and wanted to modify it ...

    :(

     
    • Anobium

      Anobium - 2022-08-13

      I would not worry.

       
    • William Roth

      William Roth - 2022-08-14

      I can no longer Edit when using Firefox Browser. However Opera and Chrome seem ok.
      It was the AddBlocker. Disabled for this site and now editing is ok

      William

       

      Last edit: William Roth 2022-08-14
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-13

    8515 and 162 have no hardware multiplier ...

     
    • Anobium

      Anobium - 2022-08-13

      The compiler is using it... line 129 in your ASM.

      Please change HardwareMult as requested.

       
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-14

    Then there is a more serious bug in the compiler (or the inc files), since it tries to use a hardware multiplier which doesn't exist on MEGA8515 !

     
  • Anobium

    Anobium - 2022-08-14

    Sorry, this may be some confusion here.

    In the file mega8515.dat it shows.

    HardwareMult=y Set this to n.


    Front page of the 8515 datasheet....

    Features
    •High-performance, Low-power AVR® 8-bit Microcontroller
    •RISC Architecture
    – 130 Powerful Instructions
    – Most Single Clock Cycle Execution
    – 32 x 8 General Purpose Working Registers
    – Fully Static Operation
    – Up to 16 MIPS Throughput at 16 MHz
    – On-chip 2-cycle Multiplier

    The On-chip 2-cycle Multiplier is leveraged by Great Cow BASIC when HardwareMult=y. So, set to n to disable the use of MUL in the ASM but to use software multiplication.

    Does this explain?

     

    Last edit: Anobium 2022-08-14
  • Bertrand BAROTH

    Bertrand BAROTH - 2022-08-14

    There is no hardware multiplier on my older 8515 :
    https://ww1.microchip.com/downloads/en/DeviceDoc/doc2512.pdf
    You are speaking of a newer version, the ATMEGA8515-16AUR
    OK, so You are right when You write that I should disable it (I use "dinosaurs" from Atmel, before they came to Microchip)

     
    • Anobium

      Anobium - 2022-08-14

      The URL above.. shows the 'On-chip 2 cycle multiplier'.

      I know the asm you shared uses MUL as the ASM shows that and you loaded the hex and it executed. If MUL was not supported then you would have an inoperable chip.

      Have you changed the dat file? did you get correct maths?

       
1 2 > >> (Page 1 of 2)

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.