avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[avr-gcc-list] avrasm2 vs. gcc/gas for the same source


From: Knut.Schwichtenberg
Subject: [avr-gcc-list] avrasm2 vs. gcc/gas for the same source
Date: Mon, 13 Dec 2004 18:27:40 +0100
User-agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.6b) Gecko/20031205 Thunderbird/0.4

Hi folks,
I'm cross posting this mail because it trys to describe the bridge
between both worlds.
After reading the description of avrasm2 I thought it could be possible to create a source file that can be compiled by both assemblers. The idea for this came from a current project that is developed in avrasm and I want to add some C-sources. So based on the description of avrasm2 I tried to change the source so that one assembler source file can be compiled by both programs.

I've created a short assembler source and after having problems, Atmel
provided very good support. This is the test program (no deeper sense):

#ifdef __GNUC__
#define EQ1(adr, val) .equ adr, val
#define EQ2(adr, val) equ adr, val
#define PMETER(adr, val)  adr, val
#define DATA_SECTION .data
#define PROG_SECTION .text
#define EEPROM_SECTION .section .eeprom
// @ is not allowed to be the first character for a defined constant
#define _X0 \p1
#define HIGH hi8
#define LOW lo8

#else
//------------------------------------------------------------
// Defines for AVRASM2
#define EQ1(adr, val) .equ adr = val
#define EQ2(adr, val) equ adr = val
#define PMETER(adr, val)  adr = val
#define DATA_SECTION .dseg
#define PROG_SECTION .cseg
#define EEPROM_SECTION .eseg
// @ is not allowed to be the first character for a define constant
#define _X0 @0
#endif

//==============================================================================
// Handle equ, both can do  but different syntax
EQ1(    cBaudRate2500_8MHz,  3)               //;   Comment
.EQ2(    cBaudRate2500_8MHz,  3)        // Not working with avrasm2
.equ PMETER(    cBaudRate2500_8MHz,  3)

//==============================================================================
// Handle def, only avrasm GNU via cpp
#define rTrackData1 r4
    add        rTrackData1,rTrackData1         ;

;X,Y,Z pointer
#define rXL    r26
#define rXH     r27
#define rYL     r28
#define rYH     r29
#define rZL     r30
#define rZH     r31


//==============================================================================
// Variable definition including fixed addresses
DATA_SECTION
.org    0x100
mXNetAddr:        .byte    1                        ;
mMM2Pause1:        .byte    2                        ;
mSigInputB:        .byte    1


//==============================================================================
// Macros
// Macro 1 Simply a macro
.macro    PUSH_YPointer
         push    rYH
         push    rYL
// Both assembler understand .endm no need for a define
.endm
//--------------------------------------------------------
// Macro 3 with parameter: different macro definition for AVRASM and gas
#ifdef __GNUC__
.macro        LDIY p1
#else
.macro        LDIY
#endif
// Using #ifdef in this position (before and after a .macro directive)
// won't work with avrasm2. ATMEL's comment


        ldi        rYH, HIGH(_X0)            //; High value
        ldi        rYL, LOW (_X0)            //; Low value
// Macro argument subsitution fails here (avrasm2 bug) ATMEL's comment

.endm

//==============================================================================
// Program with a defined address
PROG_SECTION
.org 0x10
         rjmp    reset                            ;
reset:
         PUSH_YPointer
         LDIY    mSigInputB                        //;

//==============================================================================
// eeprom Segment
EEPROM_SECTION
.org 0
eXNetAdr:        .byte    1                        ;


-----------------------------------------------------------------------------------
To compile the testprogram with the WinAVR makefile save it to a
"test.S" and compilation is okay. If you try to assemble it with avrasm2
it is not possible because for this case the buildin "preprocessor" is
not strong enough. The proposal from Atmel was:

avr-cpp -P -U __GNUC__ -o test.asm test.S
avrasm2 test.asm

Atmel's comment to the preprocessor:
"The problem is more related to the fact that the AVRASM2 preprocessor
is integrated, and has some problems when mixing preprocessor directives
and assembler macros. This was done for performance reasons (avoiding
adding a separate preprocessor pass). We may change this at a later time."
"Please keep in mind that your planned use of the preprocessor is not what we perceived as a typical use. The opportunity to use a freely available external preprocessor like GNU to preprocess assembler programs has always been there, from that point of view we never needed to include preprocessor features in the assembler at all. The reason we did it anyway was to provide an easy way for users to use familiar C preprocessing directives without relying on external software."
"In the next Studio version we will include an option to run an external
program/script before and/or after the assembler when building a
program. This should make it easier for you to automate the use of an
external preprocessor in an AVR Studio project. "

But that's not all! The "_X0"/@0 is currently not working! Atmel's comment:
"This is a known bug/limitation"

A serious problem has to do with the macro definition. The syntax
between gas and avrasm is to different. My first trial to solve this is
shown above this does not work with avrasm2.

Atmel's comment:
"It is a bug, but fixing this is too major change for the next Studio
release (4.11). "

A solution without using cpp is:

#ifdef  __GNUC__
.macro    LDIY p1
    gnu macro to follow
.endm
#else
.macro    LDIY
    avrasm macro to follow
.endm
#endif

Atmel is thinking of a changing the syntax for macros to be gas like but
 at the moment compatibility to avrasm1 is more important! No need to
wait for it.

Conclusion:
At the moment to make one source file that can be compiled without
changes with avrasm/avrasm2 and gcc/gas requires the use of cpp. The
Beta 7 of avrasm2 can not be used with macros and @x-parameter. If you
use cpp to do the preprocessor job you can also use the old avrasm.

Best Regards

Knut


reply via email to

[Prev in Thread] Current Thread [Next in Thread]