Last active
August 29, 2015 14:01
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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