Friday, April 29, 2011

Is it possible to use MIPS register names with GAS (GNU assembler)?

If I use register names I get:

Error: illegal operands `add $t0,$zero,$zero'

If I use register number ($8 instead of $t0 and $0 instead of $zero) it works.

(I'm using binutils 2.17).

From stackoverflow
  • The GNU assembler doesn't support symbolic register names directly. A common approach, if using gcc to drive the assembler, is to use the ".S" extension for the assembler source file (which tells gcc to pass the source through the C preprocessor before the assembler) and #include a header file containing definitions like:

    #define zero $0
    #define v0   $2
    #define v1   $3
    

    Then the assembler source can have statements like

    add v0, zero, zero
    
    Matthew Slattery : Minor quibble: `v0` and `v1` are `$2` and `$3` (`$1` is `at`)!
    Lance Richardson : You're right - that's what I get for trusting my memory, will correct.
  • Note: the symbolic names are supported in binutils 2.18 onwards.

0 comments:

Post a Comment