C++代码

#include<iostream>
#include <string>
using namespace std;

int main(int argc, char** argv){

    //cout<<argc<<endl;
    for (int i=1; i<argc; i++) {
    //cout<<argv[i]<<endl;
    string cmd = "nasm -f elf64 "+string(argv[i])+".asm -o "+string(argv[i])+".o";
    //system(cmd);
    system(cmd.data());
    cmd = "ld -o "+string(argv[i])+" "+string(argv[i])+".o";
    system(cmd.data());
    cmd = "./" + string(argv[i]);
    cout<<"×××××开始运行×××××"<<endl;
    system(cmd.data());
    cout<<"×××××结束运行×××××"<<endl;

    }
    return 0;
}

运行方式

./run helloworld

helloworld.asm

[section .data]         ;  // 数据在此
    strHello db "helloworld!", 0Ah
    STRLEN equ $ - strHello
    [section .text]  ; // 代码在此
    global _start    ; // 我们必须导出 _start这个入口,以便让链接器识别
 
_start:
    mov edx, STRLEN
    mov ecx, strHello
    mov ebx, 1
    mov eax, 4    ;  sys_write
    int 0x80         ;  系统调用
    mov ebx, 0
    mov eax, 1    ;  sys_exit
    int 0x80         ;  系统调用
 
Last modification:October 31st, 2020 at 10:56 am
如果觉得我的文章对你有用,请随意赞赏