|
|
|
|
|
by surki
5358 days ago
|
|
Doing it in C with mixed assembly [surki@linux-vrse tt]$ cat | gcc -nostdlib -x c - -o helloworld
#define SYS_exit 1
#define SYS_write 4
#define stdout 1
int strlen(const char *str)
{
long len = 0;
while (str && *str++)
{
len++;
}
return len;
}
void print(const char *str)
{
int len = strlen(str);
long ret;
/* Can't touch ebx directly, PIC uses it */
__asm__ __volatile__ ("pushl %%ebx\n"
"movl %%esi, %%ebx\n"
"int $0x80\n;"
"popl %%ebx"
"a" (SYS_write),
"S" ((long) stdout),
"c" ((long) str),
"d" ((long) len));
return;
}
void _start()
{
main();
__asm__ __volatile__ (
"xorl %%ebx, %%ebx\n"
"int $0x80\n"
"a" (SYS_exit));
}
int main()
{
print("Hello World\n");
return 0;
}
[surki@linux-vrse tt]$ strip -R .comment -R .comment.SUSE.OPTs -R .note.gnu.build-id helloworld
[surki@linux-vrse tt]$ ll helloworld
-rwxr-xr-x 1 suresh users 540 2010-07-21 13:19 helloworld
[surki@linux-vrse tt]$ ./helloworld
Hello World
|
|