? assembler in .S files

Go To Last Post
14 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi,

recently using AVR-GCC, i am looking for document where i can find difference between AVR assembler and GCC assembler. For example, operators LOW or HIGH seems not allowed, directives .EQU must be replaced by #define, etc... What about .MACRO ?

Is there such a document ?

Thank you

         Hervé

This topic has a solution.
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

operators LOW or HIGH seems not allowed,

Try lo8 (1234) and hi8 (1234). Have you looked in the help file?

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

The GNU as manual is here:

 

https://sourceware.org/binutils/...

 

Its version of "macro" is covered here:

 

https://sourceware.org/binutils/...

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you very much to js & clawson.

lo8 and hi8 work fine.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I don't think I've ever seen a comparison of the gnu and atmel assemblers.  Gnu documents their assembler, and Atmel documents theirs. :-(

 

directives .EQU must be replaced by #define

 #define does something different than .EQU

The gnu assembler does have directives more like .EQU, but with a slightly different syntax:

 

.equ symbol, expression

Set the value of symbol to expression. This assembler directive can also be specified as .set or as “=”. The following three lines are exactly identical, and set the value of adams to 42:

           .equ    adams, (5 * 8) + 2
           .set    adams, 0x2A
   adams   =       0b00101010
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

thank you westfw,

I also try this

    ldi r16,OSC_RC2MCREF_XOSC32K_gc

but i got "undefined reference to `OSC_RC2MCREF_XOSC32K_gc'"

if i do it in .C file : int toto=OSC_RC2MCREF_XOSC32K_gc; it is OK !

I think this is because it is defined like this :

typedef enum OSC_RC2MCREF_enum
{
    OSC_RC2MCREF_RC32K_gc = (0x00<<0),  /* Internal 32.768 kHz RC Oscillator */
    OSC_RC2MCREF_XOSC32K_gc = (0x01<<0),  /* External 32.768 kHz Crystal Oscillator */
} OSC_RC2MCREF_t;

Is there special syntax for enum ?

 

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

I think this is because it is defined like this :

You are right. avr-as knows nothing about typedef/enum/struct so you will find that device header files are structured as:

#if !defined( __ASSEMBLER__ )
 // stuff with typedef, struct, enum, etc
#endif
// stuff that the assembler does understand

Within that you can only use the "// stuff that the assembler does understand".

 

For most things Atmel headers define both a "C like" definition (struct, typedef, enum) of something but also a plain #define (with a slightly different name) in the section the assembler does understand.

 

Having said that I just looked at a typical Xmega header file and while they have an enum for use in C on this occasion they have NOT provided a plain #define variant for use in Asm. So you will have to take:

typedef enum OSC_RC32MCREF_enum
{
    OSC_RC32MCREF_RC32K_gc = (0x00<<1),  /* Internal 32.768 kHz RC Oscillator */
    OSC_RC32MCREF_XOSC32K_gc = (0x01<<1),  /* External 32.768 kHz Crystal Oscillator */
} OSC_RC32MCREF_t;

and just do something like

#define    OSC_RC32MCREF_RC32K_asm  (0x00<<1)  /* Internal 32.768 kHz RC Oscillator */
#define    OSC_RC32MCREF_XOSC32K_asm  (0x01<<1)  /* External 32.768 kHz Crystal Oscillator */

or words along those lines. To me this does seem to an oversight on Atmel's part - to put something in the "C only" section of the header with no equivalent in the C+Asm section of the file. For other things like PORTB.DIR they also define an Asm friendly PORTB_DIR in the C+Asm section.

 

OTOh who in their right mind programs a chip like Xmega in Asm eh? cheeky

Last Edited: Fri. Jan 16, 2015 - 12:34 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you clawson,

I only changed

   ldi r16,OSC_RC2MCREF_XOSC32K_gc

to

  ldi r16,(0x01<<1)          //OSC_RC2MCREF_XOSC32K_gc 

perhaps i will add this definition in my asm.h file where there already are things like "#define zl r30", "#define zh r31", etc... frown

      Hervé

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Yes that's a little annoying that all the *_gc is missing in assembler.

If you do a lot of assembler you can generate them yourself.

 

I do it (well once did it) like this in a Makefile (in *NIX)

$(TARGET).S: xmega_gc.h
xmega_gc.h:
        echo '#include <avr/io.h>' | \
        avr-gcc -mmcu=$(MCU) -E - | \
        sed -n '/=/s/^\(.*\)/#define \1/;s/[=,]//gp' > xmega_gc.h

which generates a xmega_gc.h like this if $(MCU)=xmega128a1

#define     CCP_SPM_gc  (0x9D<<0)
#define     CCP_IOREG_gc  (0xD8<<0)
#define     CLK_SCLKSEL_RC2M_gc  (0x00<<0)
#define     CLK_SCLKSEL_RC32M_gc  (0x01<<0)
#define     CLK_SCLKSEL_RC32K_gc  (0x02<<0)
#define     CLK_SCLKSEL_XOSC_gc  (0x03<<0)
#define     CLK_SCLKSEL_PLL_gc  (0x04<<0)
#define     CLK_PSADIV_1_gc  (0x00<<2)
#define     CLK_PSADIV_2_gc  (0x01<<2)
#define     CLK_PSADIV_4_gc  (0x03<<2)
#define     CLK_PSADIV_8_gc  (0x05<<2)
#define     CLK_PSADIV_16_gc  (0x07<<2)
#define     CLK_PSADIV_32_gc  (0x09<<2)
#define     CLK_PSADIV_64_gc  (0x0B<<2)
#define     CLK_PSADIV_128_gc  (0x0D<<2)
#define     CLK_PSADIV_256_gc  (0x0F<<2)
#define     CLK_PSADIV_512_gc  (0x11<<2)
#define     CLK_PSBCDIV_1_1_gc  (0x00<<0)
#define     CLK_PSBCDIV_1_2_gc  (0x01<<0)
#define     CLK_PSBCDIV_4_1_gc  (0x02<<0)
#define     CLK_PSBCDIV_2_2_gc  (0x03<<0)
#define     CLK_RTCSRC_ULP_gc  (0x00<<1)
#define     CLK_RTCSRC_TOSC_gc  (0x01<<1)
#define     CLK_RTCSRC_RCOSC_gc  (0x02<<1)
#define     CLK_RTCSRC_TOSC32_gc  (0x05<<1)
#define     SLEEP_SMODE_IDLE_gc  (0x00<<1)
#define     SLEEP_SMODE_PDOWN_gc  (0x02<<1)
#define     SLEEP_SMODE_PSAVE_gc  (0x03<<1)
#define     SLEEP_SMODE_STDBY_gc  (0x06<<1)
#define     SLEEP_SMODE_ESTDBY_gc  (0x07<<1)

and another 850 lines...

And that sed command is very easy to understand, isn't it devil.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

who in their right mind programs a chip like Xmega in Asm eh?

 Guess??

John Samperi

Ampertronics Pty. Ltd.

www.ampertronics.com.au

* Electronic Design * Custom Products * Contract Assembly

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

@snigelen : Thank you, it seems not-obvious to me, but perhaps i will try to modify ATxmega32A4Udef.inc file in a spreadsheet...

@js : I already did it for a data logger : 4 measuring channels and 16384 measures each second, storing results in Flash eprom. Could you do it with C ?

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Here's all _gc defines for an xmega32a4u.

 

Attachment(s): 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

smiley

Thank you very much ! it will surely help me !

 

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hi snigelen, and thanks for your help.

I did other thing very simple : modifying ATxmega32A4Udef.inc to ATxmega32A4Udef.incs just replacing "=" by "," ( EQU lines) and suppressing ".device" line smiley