This is my code for printing just the mantissa of a floating point. The value stored in $t1 is the value 0xBEDCFFFF, which has a mantissa of 10111001111111111111111. My code prints this without the one in the beginning. How do I write the clause to input a hidden bit of one or zero when it is necessary?
li $t4, 1 # Reset counters
li $t3, 23
mantloop: # Loop to mask and print each bit
ble $t3, $t4, finish # escape clause
subi $t3, $t3, 1 # subtract from the counter
srl $t2, $t2, 1 # shifting mask
and $t0, $t1, $t2 # ANDing registers
bnez $t0, printOneee # Print one or zero
printZerooo:
li $v0, 1
li $a0, 0
syscall
j mantloop # loop reset
printOneee:
li $v0, 1
li $a0, 1
syscall
j mantloop # loop reset
finish: # method complete
It's not clear what you mean by "account for". If you want to print the binary representation of an IEEE754 float, then the implied bit isn't part of it.
If you want the actual value represented by the mantissa, you need to know the exponent.
The implicit leading bit of the mantissa is 0 for denormals (when the exponent field is zero). Otherwise the implied bit is 1.
https://en.wikipedia.org/wiki/Single-precision_floating-point_format. This includes +- 0.0
, which is represented by exponent=0 mantissa=0.
If you don't have any denormals, then the leading bit is always 1. (But 0.0
counts as subnormal for this).
https://www.h-schmidt.net/FloatConverter/IEEE754.html is useful: it shows you the bits and the exponent / mantissa separately, for any input bit-pattern (hex) or decimal value like 1.234.
+- Infinity is represented by exponent=all-ones, mantissa=0. It's infinity, and there isn't really a meaning for the implied bit.
NaN is represented by exponent=all-ones, mantissa=non-zero (sign bit = either). The mantissa is the "payload" of the NaN, and is arbitrary. It only makes sense to talk about the bits that are actually there, not an implied bit.