as: MIPS Macros

1 
1 9.27.2 High-level assembly macros
1 ---------------------------------
1 
1 MIPS assemblers have traditionally provided a wider range of
1 instructions than the MIPS architecture itself.  These extra
1 instructions are usually referred to as "macro" instructions (1).
1 
1    Some MIPS macro instructions extend an underlying architectural
1 instruction while others are entirely new.  An example of the former
1 type is 'and', which allows the third operand to be either a register or
1 an arbitrary immediate value.  Examples of the latter type include
1 'bgt', which branches to the third operand when the first operand is
1 greater than the second operand, and 'ulh', which implements an
1 unaligned 2-byte load.
1 
1    One of the most common extensions provided by macros is to expand
1 memory offsets to the full address range (32 or 64 bits) and to allow
1 symbolic offsets such as 'my_data + 4' to be used in place of integer
1 constants.  For example, the architectural instruction 'lbu' allows only
1 a signed 16-bit offset, whereas the macro 'lbu' allows code such as 'lbu
1 $4,array+32769($5)'.  The implementation of these symbolic offsets
1 depends on several factors, such as whether the assembler is generating
DONTPRINTYET 11 SVR4-style PIC (selected by '-KPIC', ⇒Assembler options MIPS
 Options.), the size of symbols (*noteDirectives to override the size of
DONTPRINTYET 1DONTPRINTYET 11 SVR4-style PIC (selected by '-KPIC', ⇒Assembler options MIPS
 Options.), the size of symbols (⇒Directives to override the size of

 symbols MIPS Symbol Sizes.), and the small data limit (*note1DONTPRINTYET 1DONTPRINTYET 11 SVR4-style PIC (selected by '-KPIC', ⇒Assembler options MIPS
 Options.), the size of symbols (⇒Directives to override the size of

 symbols MIPS Symbol Sizes.), and the small data limit (⇒
 Controlling the use of small data accesses MIPS Small Data.).
1 
1    Sometimes it is undesirable to have one assembly instruction expand
1 to several machine instructions.  The directive '.set nomacro' tells the
1 assembler to warn when this happens.  '.set macro' restores the default
1 behavior.
1 
1    Some macro instructions need a temporary register to store
1 intermediate results.  This register is usually '$1', also known as
1 '$at', but it can be changed to any core register REG using '.set
1 at=REG'.  Note that '$at' always refers to '$1' regardless of which
1 register is being used as the temporary register.
1 
1    Implicit uses of the temporary register in macros could interfere
1 with explicit uses in the assembly code.  The assembler therefore warns
1 whenever it sees an explicit use of the temporary register.  The
1 directive '.set noat' silences this warning while '.set at' restores the
1 default behavior.  It is safe to use '.set noat' while '.set nomacro' is
1 in effect since single-instruction macros never need a temporary
1 register.
1 
1    Note that while the GNU assembler provides these macros for
1 compatibility, it does not make any attempt to optimize them with the
1 surrounding code.
1 
1    ---------- Footnotes ----------
1 
1    (1) The term "macro" is somewhat overloaded here, since these macros
1 have no relation to those defined by '.macro', ⇒'.macro' Macro.
1