Converting Floaters to Integers for ASM Codes
#1
Converting Floaters to Integers for ASM Codes

Mini guide to demonstrate how to change a floating point value to an integer.



Let's say f0 has our floating point value that we want to convert to integer.

Its double word value is 0x4077B000 00000000

We first run this ASM...

fctiw f0, f0

f0 is now converted to an integer, it's value is now 0xFFF80000 0000017B

We want the 17B (our integer value) from the Floating Point Register..

We run this ASM...

stfiwx f0, rX, rY

rY will be a memory address and rX is the value in a different register that will be used for the offset. 

Let's say rX is r31, and rY is r4. Let's also pretend rX = 0x000C and rY = 0x80456000.

stfiwx f0, r31, r4

At address 0x8045600C will be 0x0000017B

Side Note: fctiw rounds the integer (if needed) to its nearest whole number; aka standard rounding. Use fctiwz instead if you want to round to the lowest whole number.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)