A
Alhexx
Guest
Well, I've written a VC++ DLL for Ultima to swap bytes (especially for the LWO exporter). Swapping integers was no problem, I simply used the << and >> operators. But they don't work with floats...
However, Alhexx went to write a bit of assembler code
:
Code: [Select]
Any suggestions or better ideas?
- Alhexx
However, Alhexx went to write a bit of assembler code
Code: [Select]
Code:
// Swaps Bytes in 32-Bit IEEE Floatfloat APIENTRY SwapFloat(float *Value){ float fretVal = float(0); float* pretVal = &fretVal; // Uses VC++ Inline Assembler _asm { // Push Registers to Stack (save them) push eax push ebx push ecx push edx // Write Address of Values to ECX / EDX Register mov ecx, Value mov edx, pretVal // Read 8-Bit Values from the Float and write them to AX / BX Registers mov al, byte ptr [ecx] mov ah, byte ptr [ecx + 1] mov bl, byte ptr [ecx + 2] mov bh, byte ptr [ecx + 3] // Write them to the memory of the return Value mov byte ptr [edx] , bh mov byte ptr [edx + 1], bl mov byte ptr [edx + 2], ah mov byte ptr [edx + 3], al // Pop Registers from Stack pop edx pop ecx pop ebx pop eax } return fretVal;}
Any suggestions or better ideas?
- Alhexx