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
本文详细介绍了使用binutils进行程序构建的过程,包括如何编译和链接最小的"Hello world"程序,以及如何进行bfd库的测试。通过实例展示了使用gcc和ld工具的具体步骤,同时提到了编译器版本为gcc 4.8.4,并且bfd支持库的安装方法是通过apt-get安装binutils-dev。
1653

被折叠的 条评论
为什么被折叠?



