c,汇编互调

来源:互联网 发布:深圳优化公司 编辑:程序博客网 时间:2024/05/14 04:00
在 .asm 文件中 可按如下规则申明外部函数

ExitProcess PROTO NEAR32 stdcall, dwExitCode:DWORD  //库函数
CallCfunction PROTO C:DWORD ,: BYTE;c function  //自定义, 且带两个参数

.CODE                           ; start of main program code_test:        mov     eax, number     ; first number to EAX        add     eax, 158        ; add 158        mov     sum, eax        ; sum to memory        INVOKECallCfunction, sum;call c function        INVOKE  CallCfunction, number ; call c function        INVOKE  ExitProcess, 0  ; exit with return code 0PUBLIC _test                   ; make entry point publicEND                             ; end of source code

.c 文件中
void test();int _tmain(int argc, _TCHAR* argv[]){char char1= 0;unsigned uchar1= 0;short short1= 0;unsigned short ushort1 = 0;int int1= 0;unsigned uint1= 0;double double1= 0;float float1= 0;test();system("pause");return 0;}void CallCfunction(short sum){printf("i am a c function sum = %d\r\n", sum);}

实现 C, ASM 互调,和谐。