first commit
This commit is contained in:
commit
feddb27588
45
print.c
Normal file
45
print.c
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
long print(const void *buf, long count) {
|
||||||
|
asm volatile (
|
||||||
|
"syscall"
|
||||||
|
:
|
||||||
|
: "a"(1), "D"(1), "S"(buf), "d"(count) // RDI, RSI, RDX are used in x86-64 for write args
|
||||||
|
: "rcx", "r11", "memory"
|
||||||
|
);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void exit(int e) {
|
||||||
|
asm volatile(
|
||||||
|
"syscall"
|
||||||
|
:
|
||||||
|
: "a"(60), "D"(e)
|
||||||
|
:
|
||||||
|
);
|
||||||
|
for(;;);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
//void _start() {
|
||||||
|
char *msg = "Hello World!\n";
|
||||||
|
print(msg, 13);
|
||||||
|
return 69;
|
||||||
|
}
|
||||||
|
void __libc_start_main() {exit(main());}
|
||||||
|
|
||||||
|
/*
|
||||||
|
#if defined(__x86_64__)
|
||||||
|
printf("Compiled for x86_64 architecture\n");
|
||||||
|
#elif defined(__i386__)
|
||||||
|
printf("Compiled for x86 architecture\n");
|
||||||
|
#elif defined(__arm__)
|
||||||
|
printf("Compiled for ARM architecture\n");
|
||||||
|
#elif defined(__aarch64__)
|
||||||
|
printf("Compiled for ARM64 architecture\n");
|
||||||
|
#elif defined(__mips__)
|
||||||
|
printf("Compiled for ARM architecture\n");
|
||||||
|
#else
|
||||||
|
printf("Unknown architecture\n");
|
||||||
|
#endif
|
||||||
|
*/
|
||||||
|
|
||||||
Loading…
x
Reference in New Issue
Block a user