flat assembler
Message board for the users of flat assembler.

Index > Main > Passing structs as parameters

Author
Thread Post new topic Reply to topic
realcr



Joined: 02 Apr 2007
Posts: 39
realcr 07 Jul 2007, 11:53
Hey.

I was passing some structs pointers as arguments into my function.
things like:
Code:
struc point x,y
{
        .x        dd     x
        .y        dd     y
}    
    


However when referring it from inside my functions it isn't that tidy , more like:


Code:
func:
      label          .pnt       at ebp+8
      enter          0,0
      
      mov           esi,[.pnt]
      add          esi,4
      mov           eax,[esi]  ; Got the y!

      leave
      ret

    


There's probably a nicer way to do it , I just can't find out how.

realcr.
Post 07 Jul 2007, 11:53
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 07 Jul 2007, 15:13
You can use
Code:
virtual at esi
  .point point ?, ?
end virtual    


Then, when you do some reference like "mov eax, [.point.y]" it gets translated into "mov eax, [esi+4]".

BTW, are you aware of the PROC macro that comes in the fasm package? I you are developing for Windows I suggest you a full read to http://flatassembler.net/docs.php?article=win32 which will simplify your code.
Post 07 Jul 2007, 15:13
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 07 Jul 2007, 15:33
realcr: do it this way:

Code:
struc point x,y
{
        .x        dd     x
        .y        dd     y
}    
virtual at 0
  point point
  ;this declares point.x=0, and point.y=4
end virtual

func:
      label          .pnt       at ebp+8
      enter          0,0
      
      mov           esi,[.pnt]  ;esi = pointer to pnt structure
      mov           eax, [esi + point.x]
      mov           ebx, [esi + point.y]

      leave
      ret    
Post 07 Jul 2007, 15:33
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
realcr



Joined: 02 Apr 2007
Posts: 39
realcr 07 Jul 2007, 16:00
Great thanks loco and vid!

I get to learn something new about fasm every time you post a reply.

realcr.
Post 07 Jul 2007, 16:00
View user's profile Send private message Visit poster's website MSN Messenger ICQ Number 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-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.