Page 1 of 1

How do you alias a register?

PostPosted: Mon Apr 20, 2015 3:08 am
by Gravis
this question is more about the GNU Assembler more than anything else. i've searched and i can't find the answer via google so i'm hoping someone here knows.

how do you make an alias for a register?

i tried several things:

  • .set cycle_counter, r8
  • .equ cycle_counter, r8
  • .equiv cycle_counter, r8
  • cycle_counter = r8
  • #define cycle_counter r8
but when i try mov cycle_counter, 0x400 it always complains Error: unrecognized keyword/register name `mov cycle_counter,0x400'

any ideas?

Re: How do you alias a register?

PostPosted: Mon Apr 20, 2015 1:40 pm
by cmcconnell
#define will work if you use gcc on a file with a .S extension. (gcc will run the file through the C preprocessor before invoking the assembler.)

Re: How do you alias a register?

PostPosted: Mon Apr 20, 2015 2:25 pm
by Gravis
cmcconnell wrote:#define will work if you use gcc on a file with a .S extension. (gcc will run the file through the C preprocessor before invoking the assembler.)

arg! i was using .s instead of .S for the extension.

thanks, that works!

Re: How do you alias a register?

PostPosted: Mon Apr 20, 2015 2:51 pm
by cmcconnell
You're welcome.

I don't know if there are alternatives to using #define which might have advantages. I just stumbled upon the technique while looking through some example code. (Until I saw the example, I hadn't even realised you could use gcc, rather than as, and thus make use of the preprocessor.)