It is currently Wed Jan 20, 2021 4:04 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Move Register Value To Structure Pointer Argument
PostPosted: Mon Sep 09, 2013 3:06 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 01, 2011 9:38 am
Posts: 309
Location: France - 89220 Rogny-Les-Septs-Ecluses
Hello,

I'm trying to set the values of eax/edx to a structure pointer recieved as a procedure argument but it does not work directly in my case. As I'm very newbie in assembler, I must be doing something wrong.

I have a code like this:
Code:
Procedure GetPosition( *out.sf::Vector2i, *window.sf::Window )
  sfWindow_getPosition( *window )
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    !mov [p.p_out],eax
    !mov [p.p_out+4],edx
  CompilerElse
    ; TODO
  CompilerEndIf
EndProcedure
and it does not work.

sf::Vector2i is a simple structure defined in a Module:
Code:
Structure Vector2i
  x.l
  y.l
EndStructure

I have a variant working, by using a local variable:
Code:
Procedure GetPosition( *out.sf::Vector2i, *window.sf::Window )
  Protected vout.sf::Vector2i
  sfWindow_getPosition( *window )
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    !mov [p.v_vout],eax
    !mov [p.v_vout+4],edx
    *out\x = vout\x
    *out\y = vout\y
  CompilerElse
    ; TODO
  CompilerEndIf
EndProcedure
This code above works correctly.

What should I do to set the value directly to the structure pointer argument, without the need to use a local variable ?

_________________
guy rabiller | radfac founder / ceo | raafal.org


Top
 Profile  
Reply with quote  
 Post subject: Re: Move Register Value To Structure Pointer Argument
PostPosted: Mon Sep 09, 2013 4:34 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 01, 2011 9:38 am
Posts: 309
Location: France - 89220 Rogny-Les-Septs-Ecluses
I have it working for x64 (but still with a local variable).

Feel free to tell me if I'm doing something wrong:
Code:
Procedure GetPosition( *out.sf::Vector2i, *window.sf::Window )
  sfWindow_getPosition( *window )
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
    Protected vout.sf::Vector2i
    !mov [p.v_vout],eax
    !mov [p.v_vout+4],edx
    *out\x = vout\x
    *out\y = vout\y
  CompilerElse
    Protected vout.q
    !mov [p.v_vout],rax
    *out\x = vout & $FFFF
    *out\y = vout >> 32
  CompilerEndIf
EndProcedure

It works on Windows, but can I assume it will work on Linux & MacOSX ?

_________________
guy rabiller | radfac founder / ceo | raafal.org


Top
 Profile  
Reply with quote  
 Post subject: Re: Move Register Value To Structure Pointer Argument
PostPosted: Mon Sep 09, 2013 5:34 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 01, 2011 9:38 am
Posts: 309
Location: France - 89220 Rogny-Les-Septs-Ecluses
Nevermind, I got it to set the structure pointer (almost) directly (on x86):
Code:
Procedure GetPosition( *out.sf::Vector2i, *window.sf::Window )
  sfWindow_getPosition( *window )
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      !mov ecx,[p.p_out]
      !mov [ecx],eax
      !mov [ecx+4],edx
  CompilerElse
    Protected vout.q
    !mov [p.v_vout],rax
    *out\x = vout & $FFFF
    *out\y = vout >> 32
  CompilerEndIf
EndProcedure

_________________
guy rabiller | radfac founder / ceo | raafal.org


Top
 Profile  
Reply with quote  
 Post subject: Re: Move Register Value To Structure Pointer Argument
PostPosted: Mon Sep 09, 2013 7:09 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 01, 2011 9:38 am
Posts: 309
Location: France - 89220 Rogny-Les-Septs-Ecluses
I also got it for x64:
Code:
Procedure GetPosition( *out.sf::Vector2i, *window.sf::Window )
  sfWindow_getPosition( *window )
  CompilerIf #PB_Compiler_Processor = #PB_Processor_x86
      !mov ecx,[p.p_out]
      !mov [ecx],eax
      !mov [ecx+4],edx
  CompilerElse
      !mov rdx,[p.p_out]
      !mov [rdx],rax
  CompilerEndIf
EndProcedure

Sorry for noise :?

Anyway, this may help other ASM newbies like me at some point.

Cheers,
Guy.

_________________
guy rabiller | radfac founder / ceo | raafal.org


Top
 Profile  
Reply with quote  
 Post subject: Re: Move Register Value To Structure Pointer Argument
PostPosted: Mon Sep 09, 2013 9:11 pm 
Offline
Addict
Addict
User avatar

Joined: Tue Nov 09, 2010 10:15 pm
Posts: 1719
I saved this in case I ever need to reference it; thanks for sharing.

If you are trying to do it in asm, I'd guess it is for speed...if so, why not make it a macro?


Top
 Profile  
Reply with quote  
 Post subject: Re: Move Register Value To Structure Pointer Argument
PostPosted: Tue Sep 10, 2013 4:57 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Jun 01, 2011 9:38 am
Posts: 309
Location: France - 89220 Rogny-Les-Septs-Ecluses
I'm using ASM because there is no other way to do it :wink:

And yes, I should use a Macro, would be cleaner :D

_________________
guy rabiller | radfac founder / ceo | raafal.org


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 1 guest


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

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye