As I commented, writing the result to memory-mapped I/O has nothing to do with the problem of float->string conversion. Those are basically two separate steps. For parts of the algorithm that generate results in printing order, you could send them to MMIO directly instead of storing to a string in memory if you want.
This could overlap time spent calculating with time spend waiting for the low bit of 0xffff + 8
to become zero, which apparently means the MMIO register at0xffff + 12
is ready to accept another store, according to the loop in your code.
Related: How to input and output real numbers in assembly language. I only answered the input (string->float) part, unfortunately.
float->string may be easier. Probably you want to split into integer and fractional parts.
Get the integer part (as a float, in case it's too big for a 32-bit integer) and maybe divide by a large power of 10 until it fits in an int. Then you can convert to int and use a fast integer conversion for that chunk of digits. I guess use an FP remainder / modulo calculation to get the least significant part of the integer part, if you had to divide by 10^9 or something to make it fit. (It may take more than one division by 10^9 to get it down to fitting in 2^32).
For the fractional part, implement this in asm:
print a '.'
while(frac != 0) {
frac *= 10.0;
double intpart = floor(frac); // or trunc, frac should be non-negative
frac -= intpart;
store or print intpart (as a single ASCII decimal digit)
}
You probably want to use a counter to limit the number of digits printed (because it could be an infinite .999999...
or something, I think).
Use a do{}while
structure if you always want to print .0
instead of just .
when there's no fractional part.
Most FPUs directly support all of those operations with a single instruction. I'm not familiar with MIPS's FPU instruction, but I assume floor or trunc are available in hardware at least by converting to integer and back.
You could make this faster by multiplying by frac
by 100 or 10000 and using faster integer stuff. (A 2-digit integer can be split up quickly using a multiplicative inverse with an integer multiply.)