diff options
| author | verdant <im@verdant.ee> | 2026-06-01 20:44:58 +0800 |
|---|---|---|
| committer | verdant <im@verdant.ee> | 2026-06-01 20:44:58 +0800 |
| commit | 126762cc9b3322d724102ebd94ff8d4e2311c150 (patch) | |
| tree | eab28df1fcaa7465bd82f735b1bfba3a316ea491 | |
| download | no-stdlib-helloworld-126762cc9b3322d724102ebd94ff8d4e2311c150.tar.gz no-stdlib-helloworld-126762cc9b3322d724102ebd94ff8d4e2311c150.zip | |
Initial commit
| -rw-r--r-- | Makefile | 33 | ||||
| -rw-r--r-- | helloworld.c | 4 | ||||
| -rw-r--r-- | syscall.s | 14 |
3 files changed, 51 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5c48466 --- /dev/null +++ b/Makefile @@ -0,0 +1,33 @@ +CC = gcc +AS = as +LD = ld + +CFLAGS = -c -nostdlib -fno-builtin +ASFLAGS = -c + +LDFLAGS = -entry main -z noexecstack + +TARGET = helloworld +OBJS = syscall.o helloworld.o + +all: $(TARGET) + +$(TARGET): $(OBJS) + $(LD) $(OBJS) $(LDFLAGS) -o $@ + +helloworld.o: helloworld.c + $(CC) $(CFLAGS) $< -o $@ + +syscall.o: syscall.s + $(AS) $(ASFLAGS) $< -o $@ + +clean: + rm -f $(OBJS) $(TARGET) + +run: $(TARGET) + ./$(TARGET) + +size: $(TARGET) + stat -c "%s bytes" $(TARGET) + +.PHONY: all clean run size diff --git a/helloworld.c b/helloworld.c new file mode 100644 index 0000000..5d89a54 --- /dev/null +++ b/helloworld.c @@ -0,0 +1,4 @@ +int main() { + write(1, "hello world", 12); + exit(0); +} diff --git a/syscall.s b/syscall.s new file mode 100644 index 0000000..cf3cacb --- /dev/null +++ b/syscall.s @@ -0,0 +1,14 @@ +.intel_syntax noprefix + +.global write +.global exit + + +write: + mov rax, 1 + syscall + ret + +exit: + mov rax, 60 + syscall |
