Nios II Pseudoinstructions

Pseudoinstruction Equivalent Instruction
bgt rA, rB, label blt rB, rA, label
bgtu rA, rB, label bltu rB, rA, label
ble rA, rB, label bge rB, rA, label
bleu rA, rB, label bgeu rB, rA, label
cmpgt rC, rA, rB cmplt rC, rB, rA
cmpgti rB, rA, IMMED cmpgei rB, rA, (IMMED+1)
cmpgtu rC, rA, rB cmpltu rC, rB, rA
cmpgtui rB, rA, IMMED cmpgeui rB, rA, (IMMED+1)
cmple rC, rA, rB cmpge rC, rB, rA
cmplei rB, rA, IMMED cmplti rB, rA, (IMMED+1)
cmpleu rC, rA, rB cmpgeu rC, rB, rA
cmpleui rB, rA, IMMED cmpltui rB, rA, (IMMED+1)
mov rC, rA add rC, rA, r0
movhi rB, IMMED orhi rB, r0, IMMED
movi rB, IMMED addi rB, r0, IMMED
movia rB, label orhi rB, r0, %hiadj(label)
addi rB, r0, %lo(label)
movui rB, IMMED ori rB, r0, IMMED
nop add r0, r0, r0
subi, rB, rA, IMMED addi rB, rA, IMMED

Assembler Macros

macroDescriptionOperation
%lo(immed32) Extract bits [15..0] of immed32 immed32 & 0xffff
%hi(immed32) Extract bits [31..16] of immed32 (immed32 >> 16) & 0xffff
%hiadj(immed32) Extract bits [31..16] and adds bit 15 of immed32 (immed32 >> 16) + 0xffff +
((immed32 >> 15) & 0x1)
%gprel(immed32) Replace the immed32 address with an offset
from the global pointer (1)
immed32 _gp

nios_macros.m

.ifndef _nios2_macros_
.equ _nios2_macros_,1

#--------------------
# GEQU symbol, value
#
# Macro to define a global symbol
.macro  GEQU sym,val
.global \sym
.equ \sym,\val
.endm

#--------------------
# GFUNC symbol
#
# Macro to define a global function
.macro  GFUNC sym
.global \sym
.type \sym, @function
\sym:
.endm

#--------------------
# MOVI32 $reg, imm32
#
# Macro to move a 32-bit immediate into a register.
.macro  MOVI32 reg, val
   movhi \reg, %hi(\val)
   ori \reg, \reg, %lo(\val)
.endm

#--------------------
# MOVIA $reg, address
#
# Macro to move a 32-bit address into a register.
.macro  MOVIA reg, addr
   movhi \reg, %hi(\addr)
   ori \reg, \reg, %lo(\addr)
.endm

# +----------------------------
# | MOVIK32 reg,value
# |
# | for constants only, no linker action
# | uses only one instruction if possible
# |

.macro MOVIK32 _dst,_val
.if   (\_val & 0xffff0000) == 0
     MOVUI \_dst,%lo(\_val)
.elseif (\_val & 0x0000ffff) == 0
     MOVHI \_dst,%hi(\_val)
.else
     MOVHI \_dst,%hi(\_val)
     ORI   \_dst,\_dst,%lo(\_val)
.endif
.endm


.endif # _nios2_macros_

# end of file


Maintained by John Loomis, last updated 1 Sept 2008