The MASM Forum Archive 2004 to 2012

General Forums => The Workshop => Topic started by: JW_Post on August 04, 2011, 10:30:55 PM

Title: MS inline assembler confusion
Post by: JW_Post on August 04, 2011, 10:30:55 PM
// 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

Title: Re: MS inline assembler confusion
Post by: clive on August 05, 2011, 01:41:42 AM
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]
  }

Title: Re: MS inline assembler confusion
Post by: JW_Post on August 05, 2011, 01:51:42 PM
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.
Title: Re: MS inline assembler confusion
Post by: dedndave on August 05, 2011, 02:09:26 PM
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
Title: Re: MS inline assembler confusion
Post by: JW_Post on August 05, 2011, 05:21:19 PM
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.