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;
}