News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

MS inline assembler confusion

Started by JW_Post, August 04, 2011, 10:30:55 PM

Previous topic - Next topic

JW_Post

// I'm trying to do some inline assembler with MS VC, I have limited assembler experience
// and kinda stumped on some values I'm getting on a mov ?

// in the VC debugger I have verified at runtime the following
// values

// addr of ppSafe is 00419178,
// which holds (pts to)-> 0041917c (which is addr of pSafe)

// addr of  pSafe is 0041917c,
// which holds (pts to)-> 00419180 (which is addr of Safe)

// addr of Safe is 00419180,
// which holds 0041917c (which is addr of pSafe)

// but after the above is intialized and verified, when I do this
// in inline asm I have a confusing value popping up ??

mov ebx, [ppSafe] // now ebx shows 00000010 ?
push ppSafe        // so I try it with push-pop
pop ebx            // now ebx shows 00000010 ?
mov eax, [ebx] // obviously a violation at addr 10h


clive

That's because it translates that as "push [ppSafe]", and it doesn't like OFFSET or &ppSafe too generate an immediate push. Want an address, use LEA.

  __asm
  {
    lea ebx, ppSafe
    mov ebx, [ebx]
  }

It could be a random act of randomness. Those happen a lot as well.

JW_Post

Thanks, however when I try to compile I get the following,
lea ebx, ppSafe    //<- error C2415: improper operand type

//DWORD** ppSafe;  is a C++ class member of the same class as the function this asm block is in.

dedndave

hmmm
perhaps the 10h value represents the data type - not the data
there must be some operator that needs to be added to reference the variable, like % or something
%ppSafe
i think i would browse the documentation - or google a bit   :P

JW_Post

Found my answer guys, turns out the compiler doesn't know how to treat class vars like I had them.  I surmise the 10h was the next available offset on the stack current stack frame ?? not sure what it was doing.

But this code does work and gives the correct values

mov ebx, this
mov ebx, [ebx+ppSafe]

thanks for the replies.