flat assembler
Message board for the users of flat assembler.

Index > Windows > FPU help

Author
Thread Post new topic Reply to topic
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
I'm starting to jump into OpenGL and it appears to use some . numbers, so i'm guessing that somewhere along the line the FPU might become useful. Problem is, i can't learn anything about the FPU because i can't see what i'm doing. printf dosn't seem to be working with the stutff i pull back from the FPU. Does anyone know of any way i can load things into the fpu stack, mess with it, take it off the fpu stack, and output the numbers in non-rounded forms?
Post 28 May 2007, 07:34
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
FDBG contains code that can print floating values, ask Feryno
Post 28 May 2007, 11:03
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
FDBG?
Post 28 May 2007, 11:07
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Post 28 May 2007, 12:24
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Feryno



Joined: 23 Mar 2005
Posts: 465
Location: Czech republic, Slovak republic
Feryno
yeah, but fdbg sources aren't much educative...
you can freely use fpu procedures - old versions of fdbg did calculations using FPU instructions, newer use CPU to avoid some FPU-based antidebug tricks
the last version using FPU calculations is
feryno.host.sk/ms/fdbg0010.zip
read the file floating_proc.inc
usage of debugger is nice and easy way to test what the instruction does
ollydbg shows you everything in win32 and fdbg in win64

I suggest to read FASM help, chapter 2.1.13 FPU instructions
for a start, FPU behaves as a stack with limit of 8 registers
use fnitit before playing with FPU instructions (FPU may hold a mess from previous instructions...)
you can push max 8 values into st0-st7 registers
you can operate with 8 fpu registers (some instructions allow you to combine oparation with FPU register and value stored in memory)
at the end you can pop values from register or access them without poping anyway
Post 28 May 2007, 12:55
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
My computer says there's a problem with the zip, but i'll look at the other stuff. Thank you.

EDIT: Found what you're talking about. Actually, i was looking at that and going in order from top to bottom to figure out how to use the things.

EDIT2: The following is a dump from visual studio, and how to translate that into fasm is anybody's guess, but i think that it would explain how to send things to printf.

Code:
8:        float a=4.56f;
00401028   mov         dword ptr [ebp-4],4091EB85h
9:        float b=1.23f;
0040102F   mov         dword ptr [ebp-8],3F9D70A4h
10:       __asm int 3 ;placed here to intentionally crash
;the program so i could find this with ease
00401036   int         3
11:       printf("%g", a, b);
00401037   fld         dword ptr [ebp-8]
0040103A   sub         esp,8
0040103D   fstp        qword ptr [esp]
00401040   fld         dword ptr [ebp-4]
00401043   sub         esp,8
00401046   fstp        qword ptr [esp]
00401049   push        offset string "%e" (0042301c)
0040104E   call        printf (00401070)
00401053   add         esp,14h    
Post 28 May 2007, 19:14
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Plue



Joined: 15 Dec 2005
Posts: 151
Plue
printf should work. But you must tell it the argument is a floating point value and not an integer.
Post 29 May 2007, 19:40
View user's profile Send private message Reply with quote
kohlrak



Joined: 21 Jul 2006
Posts: 1421
Location: Uncle Sam's Pad
kohlrak
And if i figure out how to send it the variable, because the following dosn't work.

Code:
cinvoke printf, <"%f", 0>, 4.3    


Quote:
54376913213472293000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000000000000000000000000000000000000
0000000000000000000000000000000000000000000000000000.000000


I'd be happy if you have any example code.

EDIT: Found a nice little macro that helps called glpush, but that only works with constants, i still can't get it to work with variables. I'll keep trying to crack this...

EDIT2: Got it working. I was using the GLfloat from tomasz's opengl.inc with the opengl example, and the GLfloat is 4 bytes, but you need to push 8 bytes.

Lesson learned: Cstandard floats are 8 bytes, but the GL floats are 4 bytes. Do not use 8 bytes with gl calls and don't use 4 bytes with printf calls. You'll save yourself alot of agony that way. Aside from the differences in size, they apparently are treated the same way as each other in the FPU, so go ahead and use them.
Post 29 May 2007, 19:54
View user's profile Send private message Visit poster's website AIM Address Yahoo Messenger MSN Messenger Reply with quote
Goplat



Joined: 15 Sep 2006
Posts: 181
Goplat
kohlrak wrote:
Cstandard floats are 8 bytes, but the GL floats are 4 bytes.
Actually, in C "float" is 4 bytes and "double" is 8 bytes, but floats are automatically promoted to doubles when passed to varargs functions like *printf.
Post 29 May 2007, 22:48
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.