Skip to content

Instantly share code, notes, and snippets.

@Justasic
Last active August 29, 2015 14:01
Show Gist options
  • Save Justasic/2e2f3f84ee31ae5abacd to your computer and use it in GitHub Desktop.
Save Justasic/2e2f3f84ee31ae5abacd to your computer and use it in GitHub Desktop.
This is a hello world example on linux without using the C standard library or any dynamic libs.
unsigned long int LinuxWrite(unsigned fd, const char *str, unsigned long len)
{
unsigned long ret = -1;
__asm__ __volatile__("int $0x80" : "=a" (ret) : "a" (4), "b" (fd), "c" (str), "d" (len));
return ret;
}
void LinuxExit(int code)
{
__asm__ __volatile__ ("int $0x80" :: "a" (1), "b" (code));
}
unsigned long strlen(const char *str)
{
unsigned long len = 0;
while (*str++)
len++;
return len;
}
static inline void LinuxPuts(const char *str) { LinuxWrite(1, str, strlen(str)); }
void _start(void)
{
LinuxPuts("Hello World!\n");
LinuxExit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment