Search code examples
assemblyavrgnu-assembler

How to alias or rename the register in gas or avr-as?


For example : I need to alias temp to r16 register. In standart atmel`s compiler it can be done by .def directive:

.def temp=r16

But in avr-as(gas) it doesn`t work.

I tried this :

    .set  temp, r16 
    #define temp r16  
    #define temp $r16

This methods don`t works with registers, only with constants. I want to write like this:

    ldi temp,0xff

Please, help)


Solution

  • #define temp r16
    

    This is how I would have done it.

    However, if you use C preprocessor instructions (such as #define, #ifdef etc.), you cannot directly pass the program to as but you have to invoke the preprocessor first.

    If you are running as "indirectly" by calling gcc, you can use the file extension .S (upper-case "S") instead of .s (lower-case "s"). This tells gcc that the assembler file contains preprocessor instructions.

    Alternatively you can use the gcc command line option -x assembler-with-cpp. This tells gcc that it should ignore the file name extension and treat the file like an .S file (even if the file name ends with .c).

    Here the three options you have:

    1) gcc -o myFile.o -c myFile.S
    
    2) gcc -o myFile.o -x assembler-with-cpp -c myFile.s
    
    3) cpp -o temporaryFile.s myFile.s
       as -o myFile.o temporaryFile.s