Covered Topics

Please see the list of the topics I've covered. It's located near the bottom of the page. Thanks for stopping in!!

Thursday, November 3, 2011

QtSPIM And MIPS Instructions Using Float And Double Variables

This week, we had a lab assignment in my computer engineering class that required us to perform arithmetic operations on float variables. I quickly learned that the standard add, addi, sub, mov, ... instructions do NOT work properly on float variables. This was not explained in ANY of the literature I had prior to 15 minutes ago. Also, you apparently cannot use the standard $s0 - $s8, $t0 - $t3, ... registers for storing float or double type variables. There are special floating point registers that are used for this but are also not often discussed in the usual MIPs tutorials. So I went to Google and searched terms such as SPIM+"float variables", and SPIM+"float registers". Only then did this other information suddenly appear.

The following link should prove quite useful for anyone trying to do this:

A much more complete listing of MIPS Instructions - Including those using Float Registers

Look at pages 21 - 23 and note the instructions such as add.s, sub.s, mov.s for manipulating single precision float variables. If you are working with double precision variables, use add.d, sub.d, mov.d, ... MIPS uses a floating point coprocessor - it has special registers numbered $f0 - $f31. So, what I get from this is instead of using the $s0, $s2, and $t0 registers my professor told me to use on integers, I will have to use registers $f2, $f3, $f4, for example. Registers $f0 and $f12 are reserved in QtSPIM for reading and printing floats, respectively - so don't use them for storing/manipulating your arithmetic variables. After you perform an arithmetic operation, you will have to move that result to $f12 before you can print the answer to the console. Likewise, if your program reads a float variable from the console, you will have to fetch that number from f.p. register $f0 and place it into another - such as $f3, or wherever, before manipulating it.

If you are doing this you should get thoroughly acquainted with this document, save a copy to your hard drive, and perhaps print out your own hard copy as I have just done.

The links below show a couple short snippets of code detailing how to use these instructions.

I'll post more information on this site as it becomes available. I sincerely hope my posts on SPIM and MIPS are helping some folks. THESE posts especially have gotten a ton of hits lately - from all over the world at that!

See them at:

No comments:

Post a Comment

Constructive comments are welcome! Spam, or any abusive or profane comments will be deleted.