Hi everyone does anyone have much experience in using external
asm procedures with Visual C++

I'm try to make
my output be

Before calling my ASM procedure 4

The value of total while in my asm procedure: 15

After calling my ASM procedure 15

Press any key to continue

But the reality is I get


Before calling my ASM procedure 4

The value of total while in my asm procedure: 15

After calling my ASM procedure 4

Press any key to continue

I've tried this "ret 4" at the end of my asm file but it crashes

Here is my source

C FILE

#ifdef __cplusplus
extern "C" {
#endif
int myWonderfulProc(int);
#ifdef __cplusplus
}
#endif
#include <stdio.h>

int main()
{
register int total=4;
myWonderfulProc(total);
printf("\n %d ",total);
return 0;
}


ASSEMBLY FILE
; Filename: myWonderfulProc.asm
; Assemble options needed for ML: /c /Cx /coff

.386
.MODEL flat, C

EXTERN printf:NEAR

.DATA

formatstr db "value of total: %d ",0ah, 0


.CODE

myWonderfulProc PROC uses esi, \
total:PTR, \




add total,11

push total

mov eax, offset formatstr
push eax
call printf
pop ebx
pop ebx
pop ebx




ret
myWonderfulProc ENDP
END






:stupid:
Posted on 2001-12-06 20:53:50 by andy981
what may be incorrect with your code:

1. ebx should be preserved from your masm proc
2. if you want to change a value in your proc, you will have to pass a pointer to the value, not the value itself. So code in C:



int myWonderfulProc(int *); //<- prototype
myWonderfulProc(&total);


and in asm:



myWonderfulProc PROC C pTotal:PTR dword

mov eax,pTotal
add dword ptr [eax],11
push [eax]
mov eax, offset formatstr
push eax
call printf
add esp,8
ret
Posted on 2001-12-07 03:07:59 by japheth
It worked Great, and it added to what I found last night on the web
but do you or anyone else know how to make the above example work in C++

The example in C++ from here did not work

The C one does though! There at the bottom of the page
for Visual C++

http://www2.hawaii.edu/~sdunan/ics312/assignments/Lab05.htm

I hope this can help someone else tool
Posted on 2001-12-07 09:13:36 by andy981
What's the problem with C++? Compile/link error? Runtime error?
As far as I can see, your code snippet should work just fine in C++
(well, as long as you fix up the .asm and preserve registers that
can end up trashed).
Posted on 2001-12-07 10:32:42 by f0dder
Yes the program ,worked fine, I was refering to an example
I found else where that what may wonder about C++
It would be in that link above, but the link don't work above
Posted on 2001-12-08 08:56:23 by andy981