读书人

小弟我想用在C中调用汇编完成a+b的功能

发布时间: 2012-04-27 11:57:44 作者: rapoo

我想用在C中调用汇编完成a+b的功能,但是不知道问题出在哪儿了,求指点

C/C++ code
#include <stdio.h>#include <stdlib.h>char str1[] = "%d %d\n";char str2[] = "%d\n";int a = 0,b = 1;int main(){    _asm    {        mov eax,offset a        push eax        mov eax,offset b        push eax        mov eax,offset str2        call scanf        pop ebx        pop eax        mov a,eax        pop eax        mov b,eax        mov eax,a        push eax        mov eax,b        push eax        mov eax,offset str1        push eax        call printf        pop ebx        pop ebx        pop ebx    }    return 0;}


[解决办法]
C/C++ code
#include <stdio.h>#include <stdlib.h>int main(){    char str1[] = "%d %d";    char str2[] = "%d\n";    int a = 0,b = 1;    __asm    {        pushad        lea eax, a        push eax        lea eax, b        push eax        lea eax, str1        push eax        call scanf_s        add esp, 0xC        mov eax, a        add eax, b        push eax        lea eax, str2        push eax        call printf_s        add esp, 0x8        popad    }    system("pause");    return 0;} 

读书人网 >C++

热点推荐