C++内嵌C内嵌汇编 套娃

#include <iostream>
extern "C" {
    
#include "stdio.h"

void print()
{
    const char* s = "Hello asm\n";
    int len = 10;
    printf("Hello C\n");
    asm volatile(
        "movl $4, %%eax\n"    //sys_write
        "movl $1, %%ebx\n"    //std_out
        "movl %0, %%ecx\n"
        "movl %1, %%edx\n"
        "int $0x80      \n"
        :                //输出参数
        : "r"(s), "r"(len)      //入参
        : "eax", "ebx", "ecx", "edx"  //保留列表 不用于关联变量
    );
}
    
}

using namespace std;

int main()
{
    
    cout << "Hello Cpp" << endl;
    
    print();
    
   
    return 0;
}

程序运行输出

Hello Cpp
Hello C
Hello asm

 

上一篇:VMware ESXi虚拟机安装Windows7


下一篇:【11grac】Oracle RAC 更换存储实验