Broken OSX Demo added
authorMarkus Bröker<broeker.markus@googlemail.com>
Fri, 20 Oct 2017 06:41:27 +0200
changeset 168 dfb60716880c
parent 167 7c6b221900bf
child 169 df7c720bcaa6
Broken OSX Demo added
osx/Makefile
osx/hello.asm
osx/main.c
new file mode 100644
--- /dev/null
+++ b/osx/Makefile
@@ -0,0 +1,37 @@
+      CC = gcc -g -ggdb
+      LD = ld
+	ARCH = -arch i386
+  CFLAGS = -Wall -O2 -Iinclude
+ LDFLAGS = $(ARCH)
+    NASM = /usr/local/bin/nasm -f macho -Iinclude/
+
+  TARGETS = helloASM
+  #TARGETS+= helloC
+
+OBJECTS  = hello.o main.o
+ENTRYPOINT = entryPoint
+
+.SUFFIXES: .c .asm
+
+.c.o:
+	@echo Compiling $< ...
+	@$(CC) -c $(CFLAGS) $(ARCH) -o $@ $<
+
+.asm.o:
+	@echo Assembling $< ...
+	@$(NASM) $< -o $@
+
+all: $(TARGETS)
+
+helloC: $(OBJECTS)
+	@echo Linking $(OBJECTS) ...
+	$(CC) $(LDFLAGS) $(OBJECTS) -e $(ENTRYPOINT) -o $@
+
+helloASM: hello.o
+	@echo Linking $(OBJECTS) ...
+	$(LD) -static -e $(ENTRYPOINT) $< -o $@
+
+.PHONY: clean uninstall
+
+clean:
+	$(RM) *.o *~ $(TARGETS)
new file mode 100644
--- /dev/null
+++ b/osx/hello.asm
@@ -0,0 +1,31 @@
+section .data
+    msg db "Hello World!", 0x0a ; Die Nachricht
+    len equ $-msg
+
+section .text
+global entryPoint
+
+call entryPoint
+jmp asm_exit
+
+entryPoint:
+    push dword len      ;; Länge des Texts
+    push dword msg      ;; Der Text
+    push dword 1        ;; stdout
+
+	;; call write
+    mov eax, 0x4
+    sub esp, 4
+    int 0x80
+
+    ;; clean up 3 pushes
+    add esp, 16
+
+	ret
+	
+asm_exit:	
+    mov eax, 0x1
+	sub esp, 4
+    int 0x80
+
+	add esp, 4
new file mode 100644
--- /dev/null
+++ b/osx/main.c
@@ -0,0 +1,14 @@
+#include <stdio.h>
+#include <stdlib.h>
+
+void		entryPoint();
+
+int 
+main(int argc, char **argv)
+{
+	printf("Assembler Tutorial reloaded!\n");
+
+	entryPoint();
+
+	return EXIT_SUCCESS;
+}