problems with using ebx and ebp registers in inline assembler of MSVC

Posted on 2004-11-07
Medium Priority
Last Modified: 2008-03-06
Dear all,

Because i am running out of registers, i am forced to use ebx and ebp.
However, i run into problems in MSVC inline assember whenever i need to reference to memory location. Eg)
void fun(
  int* param1,
) {

.... i change ebx and ebp

__asm mov eax, [param1]  <-- error here (assembly listing shows _$param1[ebx]

How can i resolve this problem?

thank you
Question by:hengck23
  • 2
LVL 11

Expert Comment

ID: 12517968
I think it is the same problem you have in previous question.
You need to do the next:
__asm mov ebx, param1
__asm mov eax, [ebx]

Author Comment

ID: 12517991
Thanks for the answer.
I made a mistake. It should have been:

__asm mov eax, param1  <-- error here (assembly listing shows _$param1[ebx] )
__asm mov edx, [eax]

since ebx has already been changed, "__asm mov eax, param1 " is incorrect.
LVL 11

Expert Comment

ID: 12518110
Then you need to save and restore ebx or ebp to get proper param1 value.
Can you show your code ?
LVL 22

Accepted Solution

grg99 earned 1500 total points
ID: 12519668
You can't change bp AND access local variables.  BP points to the local variables on the stack, so you can't mess with bp and still automatically address local variables.

Alsp note if you use bp as an address register, it uses the stack segment by default, which may not be what you want


Featured Post

[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.

Question has a verified solution.

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

Exchange administrators are always vigilant about Exchange crashes and disasters that are possible any time. It is quite essential to identify the symptoms of a possible Exchange issue and be prepared with a proper recovery plan. There are multiple…
With more and more companies allowing their employees to work remotely, it begs the question: What are some of the security risks involved with remote employees and what actions should we take to secure them?
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
When cloud platforms entered the scene, users and companies jumped on board to take advantage of the many benefits, like the ability to work and connect with company information from various locations. What many didn't foresee was the increased risk…
Suggested Courses
Course of the Month15 days, 19 hours left to enroll

850 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