How do you alias a register?

How do you alias a register?

Postby Gravis » Mon Apr 20, 2015 3:08 am

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?
User avatar
Gravis
 
Posts: 445
Joined: Mon Dec 17, 2012 3:27 am
Location: East coast USA.

Re: How do you alias a register?

Postby cmcconnell » Mon Apr 20, 2015 1:40 pm

#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.)
Colin.
cmcconnell
 
Posts: 99
Joined: Thu May 22, 2014 6:58 pm

Re: How do you alias a register?

Postby Gravis » Mon Apr 20, 2015 2:25 pm

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!
User avatar
Gravis
 
Posts: 445
Joined: Mon Dec 17, 2012 3:27 am
Location: East coast USA.

Re: How do you alias a register?

Postby cmcconnell » Mon Apr 20, 2015 2:51 pm

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.)
Colin.
cmcconnell
 
Posts: 99
Joined: Thu May 22, 2014 6:58 pm


Return to Assembly

Who is online

Users browsing this forum: No registered users and 2 guests