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