It is currently Mon Oct 15, 2018 11:11 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 8:40 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 236
How can i change the content of 'Address' with inline assembly?

Code:
Code:
;PB x64 v.5.62

Procedure.i TestFnc()
  Static Address.i
  !mov qword[p.v_Address],123;<- does not work for 'Static' !
  Debug Address
EndProcedure

TestFnc()


Top
 Profile  
Reply with quote  
 Post subject: Re: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 8:46 am 
Offline
Administrator
Administrator

Joined: Fri May 17, 2002 4:39 pm
Posts: 13386
Location: France
If you want to look that, the best is to generate the assembly code with the commandline compiler (--commented switch) and look how it is named. You will save a lot of time when using inline ASM.


Top
 Profile  
Reply with quote  
 Post subject: Re: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 9:19 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 236
Fred wrote:
If you want to look that, the best is to generate the assembly code with the commandline compiler (--commented switch) and look how it is named. You will save a lot of time when using inline ASM.


Thanks :)

Heres how it works:
Code:
;-> so_PROCEDURENAME.v_VARIABLE


I found something im curious about:

If we have a Procedure that does not return a value PB does this:
Code:
...
xor rax,rax
add rsp,28
ret


However if we return a value it looks like this:
Code:
...
jmp @f
xor rax,rax
@@:
add rsp,28
ret


why is the jmp & xor even in there ?


Top
 Profile  
Reply with quote  
 Post subject: Re: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 9:28 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 3256
Location: Netherlands
Mijikai wrote:
How can i change the content of 'Address' with inline assembly?

You could do it like this
Code:
;PB x64 v.5.62

Procedure.i TestFnc()
  Static Address.i
  Protected *Address = @Address
  !mov rdx, [p.p_Address]
  !mov qword [rdx],123
  Debug Address
EndProcedure

TestFnc()

It does produce a bit of additional code and therefore is slightly slower but it does have the advantage that the reference to *Address (local variable) stays the same.
The reference to a static value changes when the procedure is included in a module.

_________________
macOS 10.14 Mojave, PB 5.62 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 10:34 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Sun Sep 11, 2016 2:17 pm
Posts: 236
wilbert wrote:
...
Code:
;PB x64 v.5.62
Procedure.i TestFnc()
  Static Address.i
  Protected *Address = @Address
  !mov rdx, [p.p_Address]
  !mov qword [rdx],123
  Debug Address
EndProcedure

TestFnc()

It does produce a bit of additional code and therefore is slightly slower but it does have the advantage that the reference to *Address (local variable) stays the same.
The reference to a static value changes when the procedure is included in a module.


Thanks, i didnt think of that way :)


Top
 Profile  
Reply with quote  
 Post subject: Re: How to access a 'Static' variable with inline assembly?
PostPosted: Fri May 11, 2018 2:46 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Thu Sep 17, 2015 3:39 pm
Posts: 114
Mijikai wrote:
...
I found something im curious about:

If we have a Procedure that does not return a value PB does this:
Code:
...
xor rax,rax
add rsp,28
ret


However if we return a value it looks like this:
Code:
...
jmp @f
xor rax,rax
@@:
add rsp,28
ret


why is the jmp & xor even in there ?



so that "PB" can be adapted to any scenario
"is complex process!"
but you can optimize that.

_________________
interested in Cybersecurity..


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 2 guests


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