Menu

Error nemonic AVR ASM inline

2018-07-08
2018-11-17
  • Agustin Hernandez

    Edit (2018-11-13) Solved in a new release v.0.98.03 (added #asmraw directive)

    Hi, I am trying to include ASM code online in programs written for AVR microcontrollers, and I found problems in instructions (mnemonics) that have the same name as BASIC instructions. For example:

    'Set chip model
    #chip tiny13,4.8
    
    mymainloop:
    and r16,r17
    andi r16,10
    com r16
    rjmp mymainloop
    

    Compile... "and r16,r17": Error: Syntax Error

    The same happens when using the assemble OR mnemonic. ¿?

    I tried to use the old ASM compiler directive:

    asm and r16,r17
    

    Compile without errors, but generate the code:

    ;asm and r16,r17
        &   R16,R17
    

    and results Error: & R16,R17 is not a valid symbol in Assemble time.

    Thank you for your help and congratulations for your work with this great compiler.

     

    Last edit: Agustin Hernandez 2018-11-13
  • Anobium

    Anobium - 2018-07-08

    You do not really need to struggle with ASM.

    '''A demonstration program for GCGB and GCB.
    '''--------------------------------------------------------------------------------------------------------------------------------
    '''This program
    '''
    '''
    '''@author
    '''@licence GPL
    '''@version
    '''@date    
    '''********************************************************************************
    
    ; ----- Configuration
      'Set chip model
    #chip tiny13,4.8
    #option Explicit
    
    dim variable1 as Byte
    dim variable2 as Byte
    
    DO forever
        variable1  = variable1  AND variable2
        variable1  = variable1  AND 0x10
        variable1 = NOT variable1
    loop
    

    There are other, far more skilled than I, who can really help if you want to use ASM. I would not - I would use the power of the compiler.

     
  • Agustin Hernandez

    Thanks for your answer Anobium.
    For ordinary processes I use the compiler, but I was testing the possibility of inserting ASM code in critical processes or when small microcontrollers do not have program space.
    Would there be possible to create a directive in the compiler to indicate blocks of programming in ASM to avoid these conflicts with the BASIC compiler? I think it would be very important to optimize critical processes.

     
  • kent_twt4

    kent_twt4 - 2018-07-08

    Don't use ASM much, but it can be useful. I think the answer might be somewhere inbetween. Using variables like Anobium suggests or strict register calls like Agustin can be worked around with minimal? overhead. Here is one way from the pwh.h include for AVR:

      'AVR prescale applied to timers
      If PWMPrescale = 1 Then
        #IFDEF AVRTC0
          If AVRTimer = 0 Then
            lds SysValueCopy,TCCR0B
            andi SysValueCopy, 0xf8
            inc SysValueCopy
            sts TCCR0B, SysValueCopy
          End If
        #ENDIF
        ...
        ...
    
     
  • Agustin Hernandez

    Hi kent_twt4, I think it's a very good idea to propose using the variable SysValueCopy instead of using the microcontroller register that can cause runtime error because the compiler does not know the registers used in the inserted ASM blocks.

    I believe that not to be able to use AND and OR instructions in the AVR assembler blocks is a mistake. I think a very simple solution would be to tell the compiler by means of some directive that a line of code or a block is written in assembler. It would be interesting that it was thought about this proposal that would facilitate the insertion of code ASM.

    Thank you.

     
  • kent_twt4

    kent_twt4 - 2018-07-09

    I see now, "andi", "com", and "ori" AVR asm instructions are correctly handled; and that, "and" and "or" are not, so I agree this should be fixed. I would raise a ticket.

    '(0.98.00 RC06) asm output
    ;or SysValueCopy, var1
    |   SYSVALUECOPY,   VAR1 ;?F1L13S0I13?
    ;and SysValueCopy, var2
    &   SYSVALUECOPY,   VAR2 ;?F1L14S0I14?
    
     
    • Anobium

      Anobium - 2018-07-09

      That does not look quite right... but, does this. :-)

      ~~~
      ASM lds SysValueCopy,TCCR0B
      ASM andi SysValueCopy, 0xf8
      ASM inc SysValueCopy
      ASM sts TCCR0B, SysValueCopy

      ~~~

      Use ASM as the prefix.

       
      • kent_twt4

        kent_twt4 - 2018-07-09

        That code works perfectly well with or without the ASM prefix.

        Augustin has pointed out that using AVR ASM instructions "and Rd,Rr" or "or Rd,Rf" do not compile correctly. See errors by trying to compile previous code of :

        and SysValCopy,var1
        or SysValCopy,var2
        
         
  • Anobium

    Anobium - 2018-07-09

    OK. On the list of issues now. :=)

     
  • Agustin Hernandez

    kent_twt4, I use 0.98.02 2018-05-10 compiler.

    The code:

    and SysValCopy,var1
    or SysValCopy,var2
    

    ERROR time compiler:

    >>>  WARNINGs / ERRORs reported by Great Cow BASIC  (if Syntax Error, doubleclick on the errormessage below)  <<<
    ASM_Code_ATTiny13.gcb (20): Error: Syntax Error
    ASM_Code_ATTiny13.gcb (21): Error: Syntax Error
    

    Code:

    ASM and SysValCopy,var1
    ASM or SysValCopy,var2
    

    No error Time Compiler but the ASM isn't correct:

    ;ASM and SysValCopy,var1
        &   sYSVALCOPY,VAR1
    ;ASM or SysValCopy,var2
        |   sYSVALCOPY,VAR2
    

    And, of course, it causes assembly error to generate the HEX file:

    Assembling program ...
    
    Errors have been found:
    
    Error: & SYSVALCOPY,VAR1 is not a valid symbol
    Error: | SYSVALCOPY,VAR2 is not a valid symbol
    

    The problem is that the compiler does not recognize the instructions OR and AND with assembler mnemonics, but rather as BASIC instructions.

     

    Last edit: Agustin Hernandez 2018-07-09
  • Anobium

    Anobium - 2018-07-09

    OK. On the list of issues now. :=)

     
  • Agustin Hernandez

    Anobium, ASM for a line seems to be already implemented, although I do not know if it works correctly (with the instructions AND and OR it does not work), but to help the compiler recognize blocks of ASM code, which seems to use compilation directives:

    #ASM
    lds SysValueCopy,TCCR0B
    andi SysValueCopy, 0xf8
    inc SysValueCopy
    sts TCCR0B, SysValueCopy
    #ENDASM
    
     
  • Anobium

    Anobium - 2018-07-10

    @Agustin.

    Thank you.

    Shown below is the reference code. We have the prefix ASM for asm blocks. We have to resolve the treatment in the compiler with respect to AND and OR.

    #chip tiny13,4.8
    #option Explicit
    
    dim variable1 as Byte
    dim variable2 as Byte
    
             ASM lds SysValueCopy,TCCR0B
             ASM andi SysValueCopy, 0xf8
             ASM inc SysValueCopy
             ASM sts TCCR0B, SysValueCopy
    
    ;error with AND and OR
    ;ASM and SysValCopy,var1
      & SYSVALCOPY,VAR1
    ;ASM or SysValCopy,var2
      | SYSVALCOPY,VAR2
            ASM and SysValCopy,var1
            ASM or SysValCopy,var2
    

    Anobium

     
  • Anobium

    Anobium - 2018-07-19

    @Agustin.

    Please send me a personal message. We have a fix for you regarding this issue. I would like you to test.

     
  • Agustin Hernandez

    Thank you. Personal message sent.

     
  • Agustin Hernandez

    :) #ASMRaw implemented in a new release v.0.98.03

    541 Fix Compiler Improvement: added #asmraw directive. Anything following this will be inserted into assembly with no changes other than trimming spaces - no replacement of constants.[769]

    Thanks!

    ... but it is not mentioned in the compiler's help. Is it a "secret directive"?

     
    😄
    1

    Last edit: Agustin Hernandez 2018-11-13
    • Anobium

      Anobium - 2018-11-14

      Seriously pleased that you read the release note!

      Pleasure.

      For those that track these things... the number as the start of the line is the change log reference and the number between the [] is the SVN commit number.

       
    • Anobium

      Anobium - 2018-11-17

      Secret directive.. no. I forgot.

      Documented now.

       
  • Anobium

    Anobium - 2018-11-17

    See https://github.com/Anobium/Great-Cow-BASIC-Help/blob/master/source/asmraw.adoc for help.

    There is a set of LXL files, CHM and helper files for those that really need. I will include in the next release.

     

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.