Skip to content

Instantly share code, notes, and snippets.

@bestknighter
Last active September 28, 2016 17:41
Show Gist options
  • Save bestknighter/fa3969c3776af0954f7693762902bf04 to your computer and use it in GitHub Desktop.
Save bestknighter/fa3969c3776af0954f7693762902bf04 to your computer and use it in GitHub Desktop.
(MIPS) Macros for loading immediate integers into Coprocessor 1's floating point registers in MARS
.macro li.s (%f_reg, %value)
addi $sp, $sp, -4 # sp++
li $at, %value # at = %value
sw $at, ($sp) # push(at)
lwc1 %f_reg, ($sp) # %f_reg = pop()
addi $sp, $sp, 4 # sp--
cvt.s.w %f_reg,%f_reg # %f_reg = (float)%f_reg
.end_macro
.macro li.d (%f_reg, %value)
addi $sp, $sp, -4 # sp++
li $at, %value # at = %value
sw $at, ($sp) # push(at)
lwc1 %f_reg, ($sp) # %f_reg = pop()
addi $sp, $sp, 4 # sp--
cvt.d.w %f_reg,%f_reg # %f_reg = (double)%f_reg
.end_macro
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment