vs nasm 汇编 混编 互调实例




asm.s




section .text ; makes this executable
global _foo , _sum_s, _printf_xs; makes this visible to linker


extern _printf
_foo:
mov eax,7 ; just return a constant
ret


_sum_s:
push ebp;
mov ebp, esp;
mov     eax, [ebp+0ch];
add     eax, [ebp+8];
pop     ebp
ret
_printf_xs:
push ebp;
mov ebp, esp;


mov     eax, [ebp+8];
push eax;
call _printf


add esp, 4;


xor eax, eax
pop     ebp
ret



c代码


#include "stdafx.h"


#include <cstdio>
#include <windows.h>


#pragma comment(lib, "user32.lib")
extern "C" int foo(void); // written in assembly!
extern "C" int sum_s(int a, int b);
extern "C" int printf_xs(char *s);
void printHelloWorld(int a)
{
        MessageBox(NULL, "Hello, World", "Greetings", MB_ICONWARNING);
}


int addx(int a, int b){
return a+b;
}
int out(char *s){
printf(s);
return 0;
}


int main(int argc, char* argv[])
{
        bool bMsgBox = false;
int a;
a = foo();
a = addx(122,1233);
a += sum_s(12,232);
out("abc\n");
printf_xs("abc123\n");
printf("%d",a);
printf("%d", foo());
        if(bMsgBox)
        {
            printHelloWorld(10);
        }
        else
        {
            printf("Hello, World");
        }
return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值