Hello World
/*TinyHelloWorld.c */
1 char * str = "Hello world!\n";
2
3 void print()
4 {
5 asm( "movl $13, %%edx \n\t"
6 "movl %0, %%ecx \n\t"
7 "movl $0, %%ebx \n\t"
8 "movl $4, %%eax \n\t"
9 "int $0x80 \n\t"
10 ::"r"(str):"edx", "ecx", "ebx");
11 }
12
13 void exit()
14 {
15 asm("movl $42, %ebx \n\t"
16 "movl $1, %eax \n\t"
17 "int $0x80 \n\t");
18 }
19
20 void nomain()
21 {
22 print();
23 exit();
24 }
/*TinyHelloWorld.lds*/
1 ENTRY(nomain)
2
3 SECTIONS
4 {
5 . = 0X08408000 + SIZEOF_HEADERS;
6
7 tinytext : { *(.text) *(.data) *(.rodata) }
8
9 /DISCARD/ : { *(.comment) }
10 }
1 /*fisrt*/
2 gcc -c -fno-builtin TinyHelloWorld.c
3
4 ld -static -e nomain -o TinyHelloWorld TinyHelloWorld.o
5
6 /*second*/
7 gcc -c -fno-builtin TinyHelloWorld.c
8
9 ld -static -T TinyHelloWorld.lds -o TinyHelloWorld TinyHelloWorld.o
10
11 /*third*/
12 gcc -c -fno-builtin TinyHelloWorld.c
13
14 ld -s -static -T TinyHelloWorld.lds -o TinyHelloWorld TinyHelloWorld.o