Just starting out? Need help? Post your questions and find answers here.
boddhi
Enthusiast
Posts: 524 Joined: Mon Nov 15, 2010 9:53 pm
Post
by boddhi » Sat May 04, 2024 1:09 am
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
Last edited by
boddhi on Sat May 04, 2024 12:22 pm, edited 1 time in total.
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
morosh
Enthusiast
Posts: 329 Joined: Wed Aug 03, 2011 4:52 am
Location: Beirut, Lebanon
Post
by morosh » Sat May 04, 2024 6:54 am
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
PureBasic : Surprisingly simple, diabolically powerful
boddhi
Enthusiast
Posts: 524 Joined: Mon Nov 15, 2010 9:53 pm
Post
by boddhi » Sat May 04, 2024 10:51 am
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 !!!
If my English syntax and lexicon are incorrect, please bear with Google translate and DeepL. They rarely agree with each other!
Except on this sentence...
Denis
Enthusiast
Posts: 778 Joined: Fri Apr 25, 2003 5:10 pm
Location: Doubs - France
Post
by Denis » Sun May 05, 2024 7:20 am
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
A+
Denis