PB6.0 Alpha 5 - Label address in datasection (?Label)

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by CSHW89 »

Hello team,

I know, there is a restriction "No Label address in datasection (?Label)". Maybe, I have a solution for that. I've analyzed a bit. The following code works with ASM backend, but not with the C backend.

Code: Select all

Structure Inner
  b.i
EndStructure

Structure Struct
  a.i
  *inner.Inner
EndStructure

Define *var.Struct
*var = ?Struct
Debug *var\a
Debug *var\inner\b

DataSection
  Struct:
  Data.i 105213214
  Data.i ?Inner
  Inner:
  Data.i 42
EndDataSection
The problem is in the C code here:

Code: Select all

unsigned char pb_data[] = {30,109,69,6,0,0,0,0
,l_inner                 // <<-----
,42,0,0,0,0,0,0,0
};
I guess you can't split the address into 8 char fields.

I tried to set the data to 0 first and manipulate it after:

Code: Select all

Structure Inner
  b.i
EndStructure

Structure Struct
  a.i
  *inner.Inner
EndStructure

; ====== CHANGE ======
! char *pointer = &pb_data[16];
! memcpy(&pb_data[8], &pointer, 8);
; ====== END ======

Define *var.Struct
*var = ?Struct
Debug *var\a
Debug *var\inner\b

DataSection
  Struct:
  Data.i 105213214
  Data.i 0;?Inner   ; <====== CHANGE ======
  Inner:
  Data.i 42
EndDataSection
Now it works. Is it possible, to implement this in the compiler? For each label in the data sections add the memcpy instruction to manipulate the pb_data array.

Thanks and best regards
Kevin
Image Image Image
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by Mijikai »

How about:

Code: Select all

Define *var.Struct
*var = ?Struct
*var\inner = ?Struct + SizeOf(Struct)
Debug *var\a
Debug *var\inner\b
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by CSHW89 »

There are many possible solutions to avoid label addresses in datasection. But I'm trying to find a solution for the compiler so that no changes to the pb code are necessary. I write a code generator that uses many addresses in datasections.
Image Image Image
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by mk-soft »

Code: Select all

Structure Inner
  b.i
EndStructure

Structure Struct
  a.i
  *inner.Inner
EndStructure

Define *var.Struct
*var = ?Struct
*var\inner = ?Inner
Debug *var\a
Debug *var\inner\b

DataSection
  Struct:
  Data.i 105213214
  Data.i 0;?Inner   ; <====== CHANGE ======
  Inner:
  Data.i 42
EndDataSection
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
CSHW89
User
User
Posts: 30
Joined: Thu Sep 09, 2010 2:47 pm

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by CSHW89 »

Yes, of course. But again, I don't want to change my code. It shouldn't be a workaround in the PB code. It's part of the PB language and the compiler should be able to handle it. My idea is a possible implementation in the compiler. For each label address in a datasection replace it with a zero and insert the two lines of code to the very beginning of the program.
Image Image Image
jackfranklin
New User
New User
Posts: 1
Joined: Wed Oct 06, 2021 10:46 am

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by jackfranklin »

I have two variables A and B defined in the .data section of an assembly program, Im trying to get A to be equal to the address of B. How can I do this? Is this possible?
User avatar
mk-soft
Always Here
Always Here
Posts: 5335
Joined: Fri May 12, 2006 6:51 pm
Location: Germany

Re: PB6.0 Alpha 5 - Label address in datasection (?Label)

Post by mk-soft »

jackfranklin wrote: Wed Oct 06, 2021 10:48 am I have two variables A and B defined in the .data section of an assembly program, Im trying to get A to be equal to the address of B. How can I do this? Is this possible?
In a DataSection there are no variables, but data or values.
So I do not understand the question.
My Projects ThreadToGUI / OOP-BaseClass / EventDesigner V3
PB v3.30 / v5.75 - OS Mac Mini OSX 10.xx - VM Window Pro / Linux Ubuntu
Downloads on my Webspace / OneDrive
Post Reply