Is there a way to switch section (.data .text .zzz) in _asm?

Started by Rainbow Sally, January 02, 2005, 04:20:45 AM

Previous topic - Next topic

Rainbow Sally

Is there a way to switch section (.data .text .zzz) in _asm?

For example is it possible to compile data in the .text section inside a function?

It may seem like a silly thing, but lets say we are writing a program in C that is not arranged like normal C code would be.  We want our code to CALL a function that will read the return address as an object pointer like this.

[Not tested -- this is just to get the concept so the question is more clear.]



// everything is __stdcall ... nothing is expected to actually work ... yet.

void* _getpointer(void *pObj);  // fwd refs ok

void * an_object(void)
{
   __asm{
   call _getpointer
   // return address will point here...
   .text? 1234 // ??? anything like this in Pelles?
   }
}

// and here's what returns the object pointer, for the record...
void* __declspec(naked) _getpointer(void *pObj)
{
 __asm{ pop eax; ret } // returns to whatever called "an_object"
}



The idea here is to use the return address as a data pointer.  Not effecient, lots of pipeline hits, apparently random alignment... I know.  And that's not the point.  Is it possible?

Anybody know how to do it?

.

Pelle

Putting data into the code section is simple: use DB, DW, DD or DQ - see Help file -> Appendix -> The Inline assembler.

Pelle
/Pelle

Rainbow Sally

I'll give them a spin shortly.  Thanks.

Quote from: "Pelle"Putting data into the code section is simple: use DB, DW, DD or DQ - see Help file -> Appendix -> The Inline assembler.

Pelle

My docs are probably outdated.  I'll look around for new docs and add-ins a bit later.