--- a/osx/Makefile
+++ b/osx/Makefile
@@ -2,14 +2,14 @@
LD = ld
ARCH = -arch i386
CFLAGS = -Wall -O2 -Iinclude
- LDFLAGS = $(ARCH)
- NASM = /usr/local/bin/nasm -f macho -Iinclude/
+ LDFLAGS = $(ARCH) -Wl,-no_pie
+ NASM = nasm -f macho32 -Iinclude -g
TARGETS = helloASM
- #TARGETS+= helloC
+ TARGETS+= helloC
OBJECTS = hello.o main.o
-ENTRYPOINT = entryPoint
+ENTRYPOINT = _entryPoint
.SUFFIXES: .c .asm
@@ -25,7 +25,7 @@
helloC: $(OBJECTS)
@echo Linking $(OBJECTS) ...
- $(CC) $(LDFLAGS) $(OBJECTS) -e $(ENTRYPOINT) -o $@
+ $(CC) $(LDFLAGS) $(OBJECTS) -o $@
helloASM: hello.o
@echo Linking $(OBJECTS) ...
--- a/osx/hello.asm
+++ b/osx/hello.asm
@@ -1,31 +1,32 @@
+global _entryPoint
+
+%define SYSCALL_EXIT 0x1
+%define SYSCALL_WRITE 0x4
+
section .data
msg db "Hello World!", 0x0a ; Die Nachricht
len equ $-msg
section .text
-global entryPoint
-call entryPoint
+call _entryPoint
jmp asm_exit
-entryPoint:
+_entryPoint:
push dword len ;; Länge des Texts
push dword msg ;; Der Text
push dword 1 ;; stdout
;; call write
- mov eax, 0x4
+ mov eax, SYSCALL_WRITE
sub esp, 4
int 0x80
;; clean up 3 pushes
add esp, 16
-
- ret
-asm_exit:
- mov eax, 0x1
+asm_exit:
+ push dword 0
+ mov eax, SYSCALL_EXIT
sub esp, 4
int 0x80
-
- add esp, 4