NO

Author Topic: Is there a way to switch section (.data .text .zzz) in _asm?  (Read 3595 times)

Rainbow Sally

  • Guest
Is there a way to switch section (.data .text .zzz) in _asm?
« on: January 02, 2005, 04:20:45 am »
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.]

Code: [Select]


// 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?

.

Offline Pelle

  • Administrator
  • Member
  • *****
  • Posts: 1974
    • http://www.smorgasbordet.com
Is there a way to switch section (.data .text .zzz) in _asm?
« Reply #1 on: January 02, 2005, 08:08:39 pm »
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

  • Guest
Is there a way to switch section (.data .text .zzz) in _asm?
« Reply #2 on: January 03, 2005, 04:02:37 am »
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.