Ok, my question:
I have and asm code like that:


public _suma

_suma proc far
push bp
mov bp,sp
mov ax,word ptr
add ax,word ptr
pop bp
ret
_suma endp



it is the asm translation of this funcion
int suma (int a, int b)
{
return (a+b);
}

i think i haven't any error here, but my question is, how do i call this from a C program. i.e. i have this


int a;
int b;
int c;

void main()
{
a = 15;
b = 10;
/*HERE I WOULD LIKE TO CALL MY ASM CODE TU ADD a AND b*/
printf("%d + %d = %d\n", a, b, c);
}


Can you help?
Posted on 2002-02-27 13:02:05 by AOA
Your asm code looks pretty 16bit-ish... here's something that
will work under 32bit, and takes advantage of masm's nice helper
stuff.



.386
.model flat,stdcall

.code
suma proc c public, v1:dword, v2:dword
mov eax, [v1]
add eax, [v2]
ret
suma endp

end


you will need to set up a prototype in your C file. For .c, use


extern int suma(int a, int b);

for .cpp, use


extern "C" int suma(int a, int b);

then you can simply do


c = suma(a, b);
Posted on 2002-02-27 13:31:48 by f0dder
My code looks 16bit-ish cos i'm working with a 486 machine (not right now, but yes to do the thing) and also using tcc and tasm version 3.0 (1992) so i'm more sure using 16 bit code.
Tomorrow i'll try it
Thanks :alright:
Posted on 2002-02-27 13:39:16 by AOA