nasm 汇编生成 windows 可执行文件

default rel 
section .text 
extern  MessageBoxA 
handler:         
sub     rsp,40              
mov     rcx,0         
lea     rdx,[text]         
lea     r8,[caption]         
mov     r9,1    ; MB_OKCANCEL         
call    MessageBoxA         
sub     eax,1   ; incidentally suits as return value     
                ; for exception handler         
add     rsp,40         
ret 
global  main 
main:         
    xor     rax,rax         
    mov     rax,QWORD[rax]  ; cause exception         
    ret 
main_end: 
text:   db      'OK to rethrow, CANCEL to generate core dump',0 
caption:db      'SEGV',0 
section .pdata  rdata align=4         
dd      main wrt ..imagebase         
dd      main_end wrt ..imagebase         
dd      xmain wrt ..imagebase 
section .xdata  rdata align=8 
xmain:  db      9,0,0,0         
dd      handler wrt ..imagebase 
section .drectve info         
    db      '/defaultlib:user32.lib /defaultlib:msvcrt.lib'
nasm -f win64 file.s
//it generate obj file 

link file.obj
//VC++ link the obj,generate exe file

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值