Implementing MIPS instructions for an absolute value function

1.9k views Asked by At

I'm really struggling in my EE class this semester and my professor goes through MIPS instructions like we're fluent in it! I've tried the book, Google, YouTube, tutoring, and talking with students, but it either doesn't make sense or they're not confident enough to help.

I really have little to no confidence in how to begin the code. I got it set up, but idk what to do. I'll provide the question and I'll update what I have as I receive help.

Question:

"Using only MIPS integer instructions, write a function that will make x = abs(y) where x and y are floating-point numbers. Your function only needs to handle normal float values correctly, not NaN, etc."

enter image description here

Attempt in the works:

(haven't made progress yet :( )

####
#
# Float absolute value
#
# x = abs(y)
# 

.text
.globl myabs

myabs:

    li $t0,y    #register t0 = y
#   more code..
#

    jr  $ra     # return

If anyone can provide some good reference material, tips, suggestions, advice, hints, or anything, I'd greatly appreciate it! Thanks.

1

There are 1 answers

9
EOF On

So, ieee754.
Read about it.
Think about it.
Realize it's signed-magnitude.
On MIPS, it so happens that the sign-bit is in the same position in the word as the most significant bit in an integer.

load float as integer x
AND x with 0x7fffffff
store x as float