binutils学习笔记

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/liushaofang/article/details/79945266

1.最小“Hello world”程序

char * str = "Hello world!\n";

void print()
{
        asm("movl $13,%%edx \n\t"
            "movl %0,%%ecx \n\t"
            "movl $0,%%ebx \n\t"
            "movl $4,%%eax \n\t"
            "int $0x80 \n\t"
            ::"m"(str):"edx","ecx","ebx");
}

void exit()
{
        asm("movl $42, %ebx \n\t"
            "movl $1, %eax \n\t"
            "int $0x80 \n\t");
}

void nomain()
{
        print();
        exit();
}

编译:gcc -c -fno-builtin TinyHelloWorld.c
链接:ld -static -e nomain -o TinyHelloWorld TinyHelloWorld.o
编译器:gcc 4.8.4

2.bfd测试代码

#include <stdio.h>
#include "bfd.h"

int main()
{
        const char * * t = bfd_target_list();
        while(*t)
        {
                printf("%s\n", *t);
                t++;
        }
        return 0;
}

bfd支持库安装:apt-get install binutils-dev
编译和链接:gcc -o bfdtest bfdtest.c -lbfd

阅读更多
想对作者说点什么?
相关热词

博主推荐

换一批

没有更多推荐了,返回首页