Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Inline Assembly with Win32 (passing values?)

Ed HallEd Hall Posts: 395Member
Hopefully this will be a simple answer. I've just never done this before.

I'd like to add a small amount of assembly coding to a Win32 (9x) program I'm building with Borland OWL C++ 4.52. I'm not familiar with passing data back. I found some code from Stober in the archives and tried to extrapolate it for my use as shown below. Will variable "a" hold the coded value when the function below returns? Do I need to concern myself with pushing and popping registers to keep from corrupting the program or is that taken care of by the normal function operations? I'm more familiar with 16 bit registers from long ago. Will 32 bit registers add any facet I should be aware of?

Does this look like I'm headed in the right direction:

[code]
int a;

void TXXWindow::function(int &a)
{
_asm
{
mov ecx,dword ptr [a]
mov eax,dword ptr [ecx]
. . .
code operations via eax register
. . .
mov dword ptr [ecx],eax
}
}
[/code]
Sorry for all the questions. Thanks for any help.

Take Care,
Ed Hall

Comments

  • stoberstober Posts: 9,765Member ✭✭✭
    [blue]Yes that will work ok. you don't need to save the general-purpose registers eax,ebx,ecx and edx. save and restore the others only if you change them.[/blue]

    : Hopefully this will be a simple answer. I've just never done this before.
    :
    : I'd like to add a small amount of assembly coding to a Win32 (9x) program I'm building with Borland OWL C++ 4.52. I'm not familiar with passing data back. I found some code from Stober in the archives and tried to extrapolate it for my use as shown below. Will variable "a" hold the coded value when the function below returns? Do I need to concern myself with pushing and popping registers to keep from corrupting the program or is that taken care of by the normal function operations? I'm more familiar with 16 bit registers from long ago. Will 32 bit registers add any facet I should be aware of?
    :
    : Does this look like I'm headed in the right direction:
    :
    : [code]
    : int a;
    :
    : void TXXWindow::function(int &a)
    : {
    : _asm
    : {
    : mov ecx,dword ptr [a]
    : mov eax,dword ptr [ecx]
    : . . .
    : code operations via eax register
    : . . .
    : mov dword ptr [ecx],eax
    : }
    : }
    : [/code]
    : Sorry for all the questions. Thanks for any help.
    :
    : Take Care,
    : Ed Hall
    :
    :

  • Ed HallEd Hall Posts: 395Member
    Thanks for your reply. I tried running a similar example, but I got some sort of "assertion" error. I then tried using the "#include NDEBUG" suggestion from the docs to no avail and I'm not learned enough to understand this part yet, so I'll dig a bit further. Thanks again.

    Take Care,
    Ed Hall

Sign In or Register to comment.