Restore from a variable.

Just starting out? Need help? Post your questions and find answers here.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Restore from a variable.

Post by jassing »

Is there a trick I can use to restore a label passed as a variable?

ie:

Code: Select all

procedure test( myLabel )
  restore (myLabel)
 ...
endprocedure

test( ?dat1 )
datasection
  dat1:
  data.b 1,2,3,4
enddatasection
citystate
Enthusiast
Enthusiast
Posts: 638
Joined: Sun Feb 12, 2006 10:06 pm

Re: Restore from a variable.

Post by citystate »

macros might do the trick

Code: Select all

Macro test(label)
  Restore label
EndMacro

test(dat1)
For i=1 To 4:Read.b a.b:Debug a:Next
test(dat2)
For i=1 To 4:Read.b a.b:Debug a:Next

DataSection
  dat2:
  Data.b 5,6,7,8
  dat1:
  Data.b 1,2,3,4
EndDataSection
there is no sig, only zuul (and the following disclaimer)

WARNING: may be talking out of his hat
User avatar
Demivec
Addict
Addict
Posts: 4277
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Restore from a variable.

Post by Demivec »

jassing wrote:Is there a trick I can use to restore a label passed as a variable?
Here's a link to a thread topic that addresses your need, 'restore label as a parameter to a procedure'.

I'll repost the resulting code from that thread here also for redundancy:

Code: Select all

Procedure RestoreEx (*address) 
 CompilerIf (#PB_Compiler_Processor = #PB_Processor_x86)
  !mov eax, [p.p_address]
  !mov [PB_DataPointer], eax
  CompilerElse   
  !mov rax, [p.p_address]
  !mov [PB_DataPointer], rax  
 CompilerEndIf
EndProcedure
The code was produced by srod with additional contributions by luis and myself.

A similar trick could be used to make note of the current value of the PB_DataPointer so that it could be restored later after an intervening read from a different data position might occur (i.e. from another thread and using a mutex) before restoring the pointer to its former position.

@Edit: added remdundant posting of complete code solution
Last edited by Demivec on Mon Nov 26, 2018 7:39 pm, edited 2 times in total.
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: Restore from a variable.

Post by jassing »

Perfect!!!

Thank you.
Post Reply