NASM 与c 交互 Window
nasm 汇编 与c 语言互相调用
nasm 在不同操作系统下,函数入口不一样,需要注意。在win 入口函数是 _mian 而在 Linux 下是start
Windows
hello.asm
global _main
extern _myprintf
section .text
_main:
push message
call _myprintf
add esp, 4
ret
message:
db 'Hello, WWrld', 10, 0
Linux
hello.asm
global start
extern _myprintf
section .text
start:
push message
call _myprintf
add esp, 4
ret
message:
db 'Hello, WWrld', 10, 0
c函数,提供给汇编使用
hello2.c
#include<stdio.h>
void myprintf(char* msg)
{
printf(msg);
}
编译过程
需要安装好 nasm 配置到环境变量中
需要使用vs2017 ,cl.exe link.exe 都是安装了,用everything 搜索配置
可以百度 cl.exe 的使用
nasm -fwin32 hello.asm
cl /c hello2.c
link hello.obj hello2.obj
环境配置
nasm 直接官网下 https://www.nasm.us/
cl link 的配置 https://www.cnblogs.com/LCCRNblog/p/4532643.html