其他分享
首页 > 其他分享> > 在VS Code中调试nasm,使用golink连接

在VS Code中调试nasm,使用golink连接

作者:互联网

VS Code非常好用,但是安装The Netwide Assembler(NASM)后,依然无法调试nasm,尝试着修改launch.json和tasks.json实现了nasm运行。

1.下载nasmx,解压缩到D:\nasmx-1.4,将bin和inc分别添加到path中。

下载连接:https://download.csdn.net/download/lordyoung/15401097

2.用VS Code打开一个Code文件夹

3.新建一个asm文件

extern __imp__MessageBoxA@16    ;in user32.dll  或是__imp_MessageBoxA@16
extern __imp__ExitProcess@4    ;in kernel32.dll 或是__imp__ExitProcess@4

global SayHello
global _main 

[SECTION .text USE32 ]
szTitle:
    db "SayHello",0
szMsg: 
    db "New World!", 0
SayHello:
    push 0                ;uType
    push dword szTitle    ;lpCaption
    push dword szMsg      ;lpText
    push 0                ;hWnd
    call [__imp__MessageBoxA@16]  ;或是__imp_MessageBoxA@16
    ret 16    

_main:
    call SayHello
    push 0
    call [__imp__ExitProcess@4]  ;或是__imp_MessageBoxA@16

4.在文件夹的.vscode目录中添加tasks.json

{
    "version": "2.0.0",
    "tasks":[
        {
            "label": "nasm",
            "type": "shell",
            "command": "D:\\nasmx-1.4\\bin\\nasm.exe",
            "args": [
                "-fwin32",
                "-o",
                "${fileDirname}\\${fileBasenameNoExtension}.obj",
                "${file}"
            ]
        },
        {
            "label": "golink",
            "type": "shell",
            "command": "D:\\nasmx-1.4\\bin\\GoLink.exe",
            "args": [
                "/entry",
                "_main",
                "${fileDirname}\\${fileBasenameNoExtension}.obj",
                "kernel32.dll",
                "user32.dll"
            ],
            "dependsOn":["nasm"]
        }
    ]    
}

5.在文件夹的.vscode目录中添加launch.json

{
    "version": "0.2.0",
    "configurations": [        
        {
            "name":"(windows)launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
            "stopAtEntry": false,        //选为true则会在打开控制台后停滞,暂时不执行程序
            "preLaunchTask": "golink",   //task的名字
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": true                        
        }        
    ]
}

6.选择文件夹asm文件,按F5就能运行,并跳出对话框了。

标签:__,Code,golink,16,imp,MessageBoxA,VS,push,nasm
来源: https://blog.csdn.net/lordyoung/article/details/113916368