下载安装mingw,大概是这样的
设置一个gcc的要用到的lib系统变量:
将要编译的hello.asm:
bits 64
default rel
segment .data
msg db "Windows10 X64 by call _CRT_INIT: Hello world!", 0xd, 0xa, 0
segment .text
global main
extern ExitProcess
extern _CRT_INIT
extern printf
main:
push rbp
mov rbp, rsp
sub rsp, 32
call _CRT_INIT
lea rcx, [msg]
call printf
xor rax, rax
call ExitProcess
先编译hello.asm为obj格式
nasm -f win64 -o hello.obj hello.asm
然后有2种方式生成exe,一种是用vsiual studio 20XX
link hello.obj /subsystem:console /entry:main /out:hello.exe kernel32.lib legacy_stdio_definitions.lib msvcrt.lib
另一种是用gcc,但_CRT_INIT这个函数怎么都找不到,后来在这个链接中找到说明
mingwrt/CRTinit.c at master · MaxKellermann/mingwrt · GitHub
先编译CRTinit.c为CRTinit.o,然后把CRTinit.o复制到上图中的LIBRARY_PATH目录下,然后用以下命令编译:
gcc -l:CRTinit.o -g -m64 hello.obj -o hello.exe
运行
hello