Search code examples
assemblyarmc-preprocessorgnupreprocessor-directive

How to give a different name to a register in GNU ARM assembler?


I have tiva c TM4C123GH6PM and I have just installed a GNU ARM tool chain. I want to program only in assembly, because I would like to a build FORTH system for it, but when I use

.equ  W, r2             // working register

this gives a symbol r2

add W, IP, #4
main.S(54): error: undefined symbol r2 used as an immediate value

then I changed to:

#define W r2

now gives

add W, IP, #4
main.S(55): error: undefined symbol W used as an immediate value

Questions:

  • Is it possible to change the name?
  • If not, can I use a C predecessor for that?

Solution

  • To create an alias for a register, use .req:

    W .req r2
    ...
    add W, IP, #4