?
Solved

MSVC inline assembler equivalent of address operator "&"?

Posted on 2004-11-07
8
Medium Priority
?
669 Views
Last Modified: 2012-06-27
Dear all,

Why can i get the address of local variables in inline assembler in MSVC?

void func(
  int* a,
  int b
){
   int c;
   int* d;

  __asm mov eax, addressOf b ?
  (in C code , it would be: eax=&c)

}

thank you.
0
Comment
Question by:hengck23
8 Comments
 
LVL 11

Assisted Solution

by:dimitry
dimitry earned 480 total points
ID: 12518019
Its address is ebp+12 in C-convention.
I think you need to use:
  __asm mov eax, offset b
0
 

Author Comment

by:hengck23
ID: 12518040
I tried the keyword OFFSET, but it doesn't work.
I think "OFFSET" only works in the main function.
0
 
LVL 11

Assisted Solution

by:dimitry
dimitry earned 480 total points
ID: 12518098
You mean OFFSET works only for Global Data... Maybe you are right.
Again it is very simple:
After:
  push ebp
  mov ebp, esp
Stack frame looks like:
  ebp                 [ebp]
  return address [ebp + 4]
  param1           [ebp + 8]
  param2           [ebp + 12]

In Pascal convention, you need to switch addresses of param1 and param2.

0
[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

 

Author Comment

by:hengck23
ID: 12518113
Hi,

I know about  "param-N          [ebp + 4+N*4]". I was just wondering is there a MARCO expression for this in MSVC inline assember.
0
 
LVL 11

Assisted Solution

by:dimitry
dimitry earned 480 total points
ID: 12518162
Can you try
  mov  eax, addr b
0
 
LVL 22

Assisted Solution

by:grg99
grg99 earned 510 total points
ID: 12519678
you want o say  :   lea    eax,[ebp+LocalVar]
0
 
LVL 9

Accepted Solution

by:
BeyondWu earned 510 total points
ID: 12520878
void func( int* a,  int b)
{
   int c;
   int* d;

   //__asm mov eax, addressOf b ?
   _asm lea eax, b
}
0
 

Author Comment

by:hengck23
ID: 12520913
I am looking for a MACRO expression. But I guess there is none. I would have to use "lea (to get address)" or ,"mov ... [EBP+ ... ] (to get value)" then.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often times it's very very easy to extend a volume on a Linux instance in AWS, but impossible to shrink it. I wanted to contribute to the experts-exchange community a way of providing a procedure that works on an AWS instance. It can also be used on…
Social messanging services like WhatsApp and Facebook can help businesses in ways that many owners don't even imagine, giving new opportunities to connect with customers. Discover some of the most innovative things they can do for your company.
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question