Home > database >  Mips Assembly why is it not branching when my float is less then zero?
Mips Assembly why is it not branching when my float is less then zero?

Time:04-29

So I have a value stored in number: .word 0 and I convert that floating point and store it in $t1 but when I use bltz to ask if the value stored in $t1 is less then zero it never branches to the "Negative" function?

   s.s $f12, number
   
   la $t0, number
   ldc1 $f2,0($t0)  # Load double floating point number
   cvt.w.d $f2, $f2
   mfc1 $t1, $f2   # Take the integer in FP Reg and put into $t1
   
 
   bltz $t1, Negative

CodePudding user response:

You're mixing data types (single float and double), so I am confused (and perhaps the processor also).

s.s stores a floating point number into memory using a floating point representation, IEEE 754, single precision, 4 bytes in size.

You then load that from that same memory location as double precision, 8 bytes in size (which it isn't) into $f2 and tell the processor to convert this double to integer.  What value do you expect to get for loading an 8-byte value when you've only provided for and stored 4 bytes?

Have you tried looking at the values in the various (e.g. floating point) registers as you're doing this?


FYI, there are floating point comparisons that the processor can use for conditional branches, without converting floating point values to integer.

  • Related