PureBasic Forum http://forums.purebasic.com/english/ |
|
How to access a 'Static' variable with inline assembly? http://forums.purebasic.com/english/viewtopic.php?f=35&t=70689 |
Page 1 of 1 |
Author: | Mijikai [ Fri May 11, 2018 8:40 am ] |
Post subject: | How to access a 'Static' variable with inline assembly? |
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() |
Author: | Fred [ Fri May 11, 2018 8:46 am ] |
Post subject: | Re: How to access a 'Static' variable with inline assembly? |
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. |
Author: | Mijikai [ Fri May 11, 2018 9:19 am ] |
Post subject: | Re: How to access a 'Static' variable with inline assembly? |
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 ? |
Author: | wilbert [ Fri May 11, 2018 9:28 am ] |
Post subject: | Re: How to access a 'Static' variable with inline assembly? |
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. |
Author: | Mijikai [ Fri May 11, 2018 10:34 am ] |
Post subject: | Re: How to access a 'Static' variable with inline assembly? |
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 ![]() |
Author: | CELTIC88 [ Fri May 11, 2018 2:46 pm ] |
Post subject: | Re: How to access a 'Static' variable with inline assembly? |
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. |
Page 1 of 1 | All times are UTC + 1 hour |
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group http://www.phpbb.com/ |