Page 1 of 1

[SOLVED] Question on label calls

Posted: Sat May 04, 2024 1:09 am
by boddhi
Hello,

Dumb question...

Below, what I'd like to achieve.
I know that a label address is "fixed" at compile time but is there a technique to recuperate and variabilize it?

Code: Select all

Procedure Test(ArgAddress)
  Protected.u Count,Counter
  Protected.s String
  
  Restore Address ; Don't work
  Read.u Count
  For Counter=1 To Count
    Read.s String
    Debug String
  Next
EndProcedure
;
Debug ?Etiq1
Address=?Etiq1
Test(Address)
Address=?Etiq2
Test(Address)
;
End
;
DataSection
Etiq1:
Data.u 1
Data.s "Test1-1"
Etiq2:
Data.u 2
Data.s "Test2-1"
Data.s "Test2-2"
Etiq3:
Data.u 3
Data.s "Test3-1"
Data.s "Test3-2"
Data.s "Test3-3"
EndDataSection


Re: Question on label calls

Posted: Sat May 04, 2024 6:54 am
by morosh
https://www.purebasic.fr/english/viewto ... 13&t=35658

Code: Select all

Procedure RestoreEx (*address) 
  ; see  http://www.purebasic.fr/english/viewtopic.php?f=13&t=35658
  
  CompilerIf #PB_Compiler_Backend = #PB_Backend_Asm
    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
  CompilerElse
    !pb_datapointer=p_address;
  CompilerEndIf
EndProcedure

DataSection
  MyData:
  Data.l 100
  MyData2:
  Data.l 200
EndDataSection

RestoreEx(?MyData)
Read.l a
Debug a

RestoreEx (?MyData2)
Read.l a
Debug a
HTH

Re: Question on label calls

Posted: Sat May 04, 2024 10:51 am
by boddhi
Hi morosh,

Thanks for the link that I don't found (Probably not the right keywords in my search).
Thanks also to all those who made this tip possible.
morosh wrote: HTH
YES !!! :wink:

Re: [SOLVED] Question on label calls

Posted: Sun May 05, 2024 7:20 am
by Denis
Hi boddhi,

another way

Code: Select all

Procedure Test(*Address)
      Protected.u Count,Counter
      Protected.s String
      
      ;   Restore Address ; Don't work
      ;   Read.u Count
      Count = PeekU(*Address) : *Address + SizeOf(unicode)
      
      For Counter = 1 To Count
            
            ;     Read.s String
            String = PeekS(*Address)
            Debug String
            
            ; SizeOf(CHARACTER) pour le zéro de fin de chaine/ SizeOf(CHARACTER) for the end-of-chain zero
            *Address + StringByteLength(String) + SizeOf(CHARACTER)
            
      Next
EndProcedure

Address=?Etiq1
Test(Address)

Address=?Etiq2
Test(Address)

Address=?Etiq3
Test(Address)

End

DataSection
      Etiq1:
      Data.u 1
      Data.s "Test1-1"
      Etiq2:
      Data.u 2
      Data.s "Test2-1"
      Data.s "Test2-2"
      Etiq3:
      Data.u 3
      Data.s "Test3-1"
      Data.s "Test3-2"
      Data.s "Test3-3"
EndDataSection