Skip to content

Instantly share code, notes, and snippets.

@maxdeliso
Last active August 29, 2015 14:25
Show Gist options
  • Save maxdeliso/a6f9734b1339df39370c to your computer and use it in GitHub Desktop.
Save maxdeliso/a6f9734b1339df39370c to your computer and use it in GitHub Desktop.
uch - messaging program written in assembly
CC=gcc
LD=ld
CFLAGS=-Wall -Wextra -pedantic -std=c11 -g
LDFLAGS=-entry run
uch: uch.o
$(LD) $(LDFLAGS) $< -o $@
uch.o: uch.c
$(CC) $(CFLAGS) -c $< -o $@
clean:
rm -f uch uch.o
#include <x86_64-linux-gnu/asm/unistd.h>
#include <stdint.h>
static _Noreturn void __exit(const uint64_t exitCode);
void run() {
__exit(0);
}
static _Noreturn void __exit(const uint64_t exitCode) {
__asm__ ("mov %[n], %%rax;"
"mov %[c], %%rdi;"
"syscall;"
: /* no output */
: [n] "i" (__NR_exit), [c] "r" (exitCode)
: "rcx", "r11" );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment