flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > problem with double in invoke macro

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Feb 2007, 15:53
I have a function that uses double floats at parameters, the positive values work fine, but when I use a negative values, I get an error.
Example:
Code:
invoke function, double 5.0 ;works    

Code:
invoke function, double -5.0 ;fails, gives me an error    
Post 08 Feb 2007, 15:53
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Feb 2007, 16:27
madmatt: haha, good catch Smile
can be easily fixed in macro, look for "match =double" and add possibility for -
Post 08 Feb 2007, 16:27
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Feb 2007, 17:37
vid: thanks Razz , However couldn't find what you suggested. I think I'll let Tomasz fix this one, my knowledge of the macro language is still near zip Sad .
Post 08 Feb 2007, 17:37
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Feb 2007, 18:02
add this to macro "pushd" in "win32ax.inc":
Code:
  
match pushd =- =double num,pushd value \{ \local ..high,..low
   virtual at 0
    dq -num
    load ..low dword from 0
    load ..high dword from 4
   end virtual
   push ..high
   push ..low
   pushd equ \}
    
Post 08 Feb 2007, 18:02
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Feb 2007, 18:55
vid, I think that your code is enabling the possibility of doing "- double 5.0" instead of "double -5.0".

Anyway the following code works with the lastest FASM without any modification:
Code:
include 'win32ax.inc'

.code
start:
  invoke  function, double -5.0
  invoke  MessageBox, 0, "Works Fine", "FASM test", 0
  invoke  ExitProcess, 0

function dd functionLabel

functionLabel: retn 8

.end start    
Post 08 Feb 2007, 18:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 08 Feb 2007, 19:11
Loco: oh sure, my mistake :]
you are right, it should work. I just realized that "match" can match more than 1 symbol. Haven't been dealing with FASM macros for some time. :S
Post 08 Feb 2007, 19:11
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Feb 2007, 21:11
I updated my includes with the latest fasmw includes Rolling Eyes, and now it works right, thanks to all for your help Very Happy.
Post 08 Feb 2007, 21:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 08 Feb 2007, 21:22
Even FASM 1.64 works. Maybe you weren't using FASM includes? Wink
Post 08 Feb 2007, 21:22
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 08 Feb 2007, 23:10
I use a modified include file, basically, I combined the win32a.inc and win32axp.inc into a single win32a.inc file. And it looks like I missed something the first time. Smile
Post 08 Feb 2007, 23:10
View user's profile Send private message Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 09 Feb 2007, 10:00
there are little problem with double in invoke macro, AFAIK, double is 8 bytes (2 DWORDs), but this code compiled with error (or i missed something?!)

Code:
  start:
        stdcall _test,double -5.0
        invoke  ExitProcess,NULL

  proc  _test, param
        ret
  endp
    


Code:
push    40140000
push    0
call    _test
push    0
call    ExitProcess

_test:
push    ebp
mov     ebp,esp
leave
retn    4  <-------- must be 8?
    
Post 09 Feb 2007, 10:00
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 09 Feb 2007, 10:42
Vasil: you must define procedure argument as QWORD, or define two arguments. Otherwise assembler cannot figure out you want it to be qword
Post 09 Feb 2007, 10:42
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Vasilev Vjacheslav



Joined: 11 Aug 2004
Posts: 392
Vasilev Vjacheslav 09 Feb 2007, 15:30
yes, it's needed to read fasm.pdf before asking stupid question, thanks

this code works ok

Code:
section '.idata' data readable writeable

  param         dq 5.0

section '.code' code readable writable executable

  start:
        stdcall _test,double param
        invoke  ExitProcess,NULL

  proc  _test, param:QWORD
        ret
  endp

    

_________________
[not enough memory]
Post 09 Feb 2007, 15:30
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Feb 2007, 15:47
Works but it doesn't pass 5.0 as parameter but a pointer to param and a NULL pointer instead.

The correct way
Code:
stdcall _test, double [param]    


BTW, I think that this one is a bug, the pushd macro should check if it really pushing a float.
Post 09 Feb 2007, 15:47
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 09 Feb 2007, 18:01
At WIN32?X*.inc
Code:
  match pushd =double num,pushd value \{ \local ..high,..low
   virtual at 0
; ### ADD THIS
    if ~num eqtype 1.0
      display "Floating point value expected"
      err
    end if
; ###
    dq num
    load ..low dword from 0
    load ..high dword from 4
   end virtual
   push ..high
   push ..low
   pushd equ \}
    
Post 09 Feb 2007, 18:01
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 09 Feb 2007, 22:47
The "double" is just a 64-bit value, it doesn't necessarily need to be a float.
Post 09 Feb 2007, 22:47
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 10 Feb 2007, 00:20
Quote:
If the parameter is preceded by the word double, it is treated as 64-bit value and passed to the procedure as two 32-bit parameters. For example:

invoke glColor3d,double 1.0,double 0.1,double 0.1

will pass the three 64-bit parameters as six double words to procedure. If the parameter following double is the memory operand, it should not have size operator, the double already works as the size override.


I found the name "double" not very good chosen then, if the word "double" is for passing a 64-bit value then why not providing the word "quad" instead? I mean, the word size of x86 architecture is 16 bits, so specifying "double" means a 32-bit value, but, if we think "double" as the HLL meaning (which the example in the quote suggests), and taking into account that the invoke macro is for provide some HLL construct, for me the appropiete behavior of "double num" is to allow only a float "num".

All the above just IMHO of course Razz
Post 10 Feb 2007, 00:20
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 10 Feb 2007, 06:38
loco: Naaaaaa Surprised , double is just fine, c++ uses double, along with all the .NET languages, and a lot of older langauges, like QuickBasic. Just remember, to pass a double to a function using var:QWORD in the proc header.
Post 10 Feb 2007, 06:38
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8351
Location: Kraków, Poland
Tomasz Grysztar 10 Feb 2007, 10:12
"double" means "double push" here: the two 32-bit parameters are pushed to the stack.
Post 10 Feb 2007, 10:12
View user's profile Send private message Visit poster's website Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 11 Feb 2007, 11:23
Still Having problems with the double, when I do this:
Code:
double -1.5    

It gives me an error, but when I do this:
Code:
double (-1.5)    

It works. I also have a function that won't compile for some reason:
Code:
invoke  glutSolidSphere, double [resulta], 20, 16    

It gives me an 'invalid parameter count', but the Parameter count is correct!
For some reason it thinks the double keyword is a variable or something.
Post 11 Feb 2007, 11:23
View user's profile Send private message Reply with quote
madmatt



Joined: 07 Oct 2003
Posts: 1045
Location: Michigan, USA
madmatt 11 Feb 2007, 12:58
I think I found the problem! After taking a closer look at the macro, I commented the 'err' word and everything worked! see below:
EDIT Correction, the negative values still give me problems, but the other error seems to be corrected.
Code:
  macro invoke proc,[arg]
  \{ \common count@stdcall = 0
             if ~ arg eq
     \forward count@stdcall = count@stdcall+1
              match =double value, arg \\{ count@stdcall = count@stdcall+1 \\}
     \common end if
             if defined proc \# %
              if count@stdcall <> proc \# %
               display "Error: invalid count of parameters for ",\`proc,".",0Dh,0Ah
               ;err  <-[RIGHT HERE]
              end if
             end if
     \reverse pushd <arg>
     \common call [proc] \}
    
[/b]
Post 11 Feb 2007, 12:58
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.