diff --git a/basics/asm/Makefile b/basics/asm/Makefile index 389fa30a813f1072c49351c526b7925d8ea54920..f38200b19f3c6da029a6424202a1941ae97cc299 100644 --- a/basics/asm/Makefile +++ b/basics/asm/Makefile @@ -1,33 +1,33 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "basic-asm" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig LDFLAGS = -static -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen ASM = nasm ASMFLAGS = -f elf64 -O0 -g -F dwarf -NAME = start # Name des Programms/der ausführbaren Datei +NAME = start # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) .PHONY: clean -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) - $(CC) $(LDFLAGS) $(CFLAGS) -o $(NAME) $(OBJS) +$(NAME): $(OBJS) + $(CC) $(LDFLAGS) $(CFLAGS) -o $(NAME) $(OBJS) -clean: - $(RM) *.o $(NAME) +clean: + $(RM) *.o $(NAME) diff --git a/basics/asm/asmfunc.asm b/basics/asm/asmfunc.asm index 9faff70996e0c63ed01f0bf5089ae37f2c43918a..390c820e9f6cb809ad638f7819cb3481bd6d0fbb 100644 --- a/basics/asm/asmfunc.asm +++ b/basics/asm/asmfunc.asm @@ -1,7 +1,7 @@ extern printf ; forward declaration of printf SECTION .data - msg db 'Hello from asmfunc!', 10, 0 + msg db 'Hello from asmfunc!', 10, 0 SECTION .text @@ -9,7 +9,7 @@ SECTION .text global asmfunc ; Funktionen implementieren -asmfunc: +asmfunc: push rbp ; neuer Stackframe erzeugen mov rbp, rsp @@ -18,7 +18,7 @@ asmfunc: ; set return value to 0 mov rax, 0 - + mov rsp, rbp ; alter Stackframe restaurieren - pop rbp + pop rbp ret ; zurueck zum Aufrufer diff --git a/basics/asm/main.asm b/basics/asm/main.asm index af5d815372be1a15f23e317e7293826ad00e26d8..d106299f942389ee6562746b435fd7d51022acb0 100644 --- a/basics/asm/main.asm +++ b/basics/asm/main.asm @@ -20,7 +20,7 @@ main: ; ersetzt werden. call asmfunc - pop rbp ; alter Stackframe restaurieren + pop rbp ; alter Stackframe restaurieren ; Programm verlassen & signalisieren, ; dass bei bei der Ausführung kein Fehler diff --git a/basics/c/Makefile b/basics/c/Makefile index c7c78cb8babcc5638170c409dc5a2a612a550178..b314f21c8ba67372ae82889f690572d6e302df11 100644 --- a/basics/c/Makefile +++ b/basics/c/Makefile @@ -1,36 +1,36 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "basic-c" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig LDFLAGS = -static -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen -ASM = nasm +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +ASM = nasm ASMFLAGS = -f elf64 -O0 -g -F dwarf -NAME = start # Name des Programms/der ausführbaren Datei +NAME = start # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) SRC = $(wildcard *.c) .PHONY: clean -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) - $(CC) $(LDFLAGS) $(CFLAGS) -o $(NAME) $(OBJS) +$(NAME): $(OBJS) + $(CC) $(LDFLAGS) $(CFLAGS) -o $(NAME) $(OBJS) -clean: +clean: $(RM) *.o $(NAME) depend: .depend diff --git a/basics/c/asmfunc.asm b/basics/c/asmfunc.asm index 862c4164b97c5dca5b92b80ff1638c4ecfd7ffab..47966e6e778234377a3e538d17769a229569bac8 100644 --- a/basics/c/asmfunc.asm +++ b/basics/c/asmfunc.asm @@ -1,7 +1,7 @@ extern printf ; externe Funktion printf deklarieren SECTION .data - msg db 'Hello from asmfunc!', 10, 0 + msg db 'Hello from asmfunc!', 10, 0 SECTION .text @@ -9,7 +9,7 @@ SECTION .text global asmfunc ; Funktionen implementieren -asmfunc : +asmfunc : push rbp ; neuer Stackframe erzeugen mov rbp, rsp @@ -18,7 +18,7 @@ asmfunc : ; Rückgabewert auf 0 setzen mov eax, 0 - + mov rsp, rbp ; alter Stackframe restaurieren - pop rbp + pop rbp ret ; Ruecksprung zum Aufrufer diff --git a/basics/einfach/Makefile b/basics/einfach/Makefile index 4a97ec0ea1e2d649e96f1d591771bc2f6b296c8a..2e8d52033cbcf1c598ff3cfa3185d0d9d43af465 100644 --- a/basics/einfach/Makefile +++ b/basics/einfach/Makefile @@ -1,36 +1,36 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "halloWelt" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig LDFLAGS = -static -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen -ASM = nasm +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +ASM = nasm ASMFLAGS = -f elf64 -O0 -g -F dwarf -NAME = start # Name des Programms/der ausführbaren Datei +NAME = start # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) SRC = $(wildcard *.c) .PHONY: clean -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) +$(NAME): $(OBJS) $(CC) $(LDFLAGS) $(CFLAGS) -o $(NAME) $(OBJS) -clean: +clean: $(RM) *.o $(NAME) depend: .depend diff --git a/basics/einfach/halloWelt.c b/basics/einfach/halloWelt.c index 140fa6e5728977d1746e1ac5407ca869cc50564e..69101269f944165e396d2bd1e6022f0863f473f3 100644 --- a/basics/einfach/halloWelt.c +++ b/basics/einfach/halloWelt.c @@ -7,15 +7,15 @@ int main() int index = -1; char lokalesArray[30] = "Hello World!!!!"; char* zeigerAufZeichenkettenkonst = "Hallo Welt!"; - + printf("%s\n", lokalesArray); - + for (index = 0; *zeigerAufZeichenkettenkonst != STR_END; index++) lokalesArray[index] = *zeigerAufZeichenkettenkonst++; - + lokalesArray[index] = STR_END; printf("\noder...\n\n%s\n", lokalesArray); - + return 0; } diff --git a/chapter2/maximum/Makefile b/chapter2/maximum/Makefile index be189f716cfa4d6c8f332786a7a375264a30ba90..319661db8fb39e71f446f4a65545acd781a8eccc 100644 --- a/chapter2/maximum/Makefile +++ b/chapter2/maximum/Makefile @@ -1,32 +1,32 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "maximum" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -m32 -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen -ASM = nasm +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +ASM = nasm ASMFLAGS = -f elf32 -O0 -g -F dwarf -NAME = maximum # Name des Programms/der ausführbaren Datei +NAME = maximum # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) .PHONY: clean -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) - $(CC) $(CFLAGS) -o $(NAME) $(OBJS) +$(NAME): $(OBJS) + $(CC) $(CFLAGS) -o $(NAME) $(OBJS) -clean: - $(RM) *.o $(NAME) +clean: + $(RM) *.o $(NAME) diff --git a/chapter2/maximum/main.asm b/chapter2/maximum/main.asm index e2e5cd653bf7cb81be95ddc1f5b0de890f14f85a..c7f5e0188255bb872e0ba608ee0ca9f60c2fff86 100644 --- a/chapter2/maximum/main.asm +++ b/chapter2/maximum/main.asm @@ -8,20 +8,20 @@ SECTION .text maximum: push ebp ; save old ebp - mov ebp, esp ; create new ebp + mov ebp, esp ; create new ebp sub esp, 4 ; create local var j mov eax, [ebp+8] ; load 42 in eax mov [ebp-4], eax ; mov 42 to j - mov eax, [ebp+12] ; load 2 in eax + mov eax, [ebp+12] ; load 2 in eax cmp eax, [ebp-4] ; compare 2 with j - jl change ; jump below to change, - mov [ebp-4], eax ; if not then move eax to j + jl change ; jump below to change, + mov [ebp-4], eax ; if not then move eax to j + +change: + mov eax, [ebp-4] ; mov j to eax -change: - mov eax, [ebp-4] ; mov j to eax - add esp, 4 ; destroy local var j pop ebp ; restore ebp ret ; jump back to addr before function was called @@ -37,7 +37,7 @@ main: add esp, 8 mov esp, ebp ; restore old stack frame - pop ebp + pop ebp ; leave program and forward maximum's result ; to the shell diff --git a/chapter2/mergesort/v1/Makefile b/chapter2/mergesort/v1/Makefile index e75445465fb3ce838b3bb586a22f26b30bcd2281..98dc8cabac8e3cfe4b1059a04c14f8250091a381 100644 --- a/chapter2/mergesort/v1/Makefile +++ b/chapter2/mergesort/v1/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -Wall -O0 -g CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = merge_v1 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/mergesort/v2/Makefile b/chapter2/mergesort/v2/Makefile index 23a6bac49e714adde237ffea5dba13773dc61a83..0b01c1e9bd0dd8f1d5924d648574d6c9fe21ec2a 100644 --- a/chapter2/mergesort/v2/Makefile +++ b/chapter2/mergesort/v2/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = merge_v2 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/mergesort/v2/main.c b/chapter2/mergesort/v2/main.c index 58a372cc64f9c0a5a656c4b03883d88393830a85..def61739fdecf9cb4f25924de7167d38a20c4039 100644 --- a/chapter2/mergesort/v2/main.c +++ b/chapter2/mergesort/v2/main.c @@ -100,7 +100,7 @@ int main(int argc, char **argv) pthread_t thread; thread_param thr_arg; - /* + /* *"seed" auf die aktuelle Zeit setzen, um * nicht immer die selben Zufallszahlen zu erhalten */ diff --git a/chapter2/pi/fpu/Makefile b/chapter2/pi/fpu/Makefile index a901bcedac62a210b1b2dfe86e86220c42b554a7..acc1d63c2f0e18d46a0637d69c11047b45ce3dd3 100644 --- a/chapter2/pi/fpu/Makefile +++ b/chapter2/pi/fpu/Makefile @@ -1,30 +1,30 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "pi_fpu" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -m32 -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen -ASM = nasm +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +ASM = nasm ASMFLAGS = -f elf32 -O0 -g -F dwarf -NAME = start # Name des Programms/der ausführbaren Datei +NAME = start # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) - $(CC) $(CFLAGS) -o $(NAME) $(OBJS) +$(NAME): $(OBJS) + $(CC) $(CFLAGS) -o $(NAME) $(OBJS) -clean: - $(RM) *.o $(NAME) +clean: + $(RM) *.o $(NAME) diff --git a/chapter2/pi/fpu/main.asm b/chapter2/pi/fpu/main.asm index 3066ef79c671829ecf40c6969388733ea4c3d574..5f3593809fb51d52eaa8c4ededca915b20135390 100644 --- a/chapter2/pi/fpu/main.asm +++ b/chapter2/pi/fpu/main.asm @@ -47,7 +47,7 @@ L1: fmul st0, st0 fld1 ; st0 = 1.0 faddp st1, st0 - + ; teile 4 durch das Zwischenergebnis fdivr qword [four] @@ -66,12 +66,12 @@ L2: push msg call printf add esp, 12 - + pop ecx pop ebx mov esp, ebp ; alter Stackframe restaurieren - pop ebp + pop ebp ; Programm verlassen & signalisieren, ; dass bei bei der Ausführung kein Fehler diff --git a/chapter2/pi/fpu64/Makefile b/chapter2/pi/fpu64/Makefile index 96bcd7de6d7dd86ac931393ee23004b17f01fb58..517c86d4c73315ee4a3ac5788910d2fbbd5a8488 100644 --- a/chapter2/pi/fpu64/Makefile +++ b/chapter2/pi/fpu64/Makefile @@ -1,30 +1,30 @@ -#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles -# werden zur ausführbaren Datei "start" zusammengebunden! -MAKE = make -CC = gcc +#ACHTUNG: alle *.asm u. *.c Dateien im Ordner dieses Makefiles +# werden zur ausführbaren Datei "pi_fpu64" zusammengebunden! +MAKE = make +CC = gcc CFLAGS = -m64 -Wall -O0 -g #-pthread, nur für POSIX-Threads notwendig -RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen -ASM = nasm +RM = rm -rf #rm = Unix-Befehl remove = Dateien löschen +ASM = nasm ASMFLAGS = -f elf64 -O0 -g -F dwarf -NAME = start # Name des Programms/der ausführbaren Datei +NAME = start # Name des Programms/der ausführbaren Datei # Objekt-Datei-Liste generieren aus Quell-Datei-Listen -OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) -OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) +OBJS = $(patsubst %.c, %.o, $(wildcard *.c)) +OBJS += $(patsubst %.asm, %.o, $(wildcard *.asm)) -# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) -%.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< +# Erzeugung von Objektdateien (*.o) aus den Quellcodedateien (*.c u. *.asm) +%.o : %.c + $(CC) -c $(CFLAGS) -o $@ $< -%.o : %.asm - $(ASM) $(ASMFLAGS) -o $@ $< +%.o : %.asm + $(ASM) $(ASMFLAGS) -o $@ $< -all: - $(MAKE) $(NAME) +all: + $(MAKE) $(NAME) -$(NAME): $(OBJS) - $(CC) -static $(CFLAGS) -o $(NAME) $(OBJS) +$(NAME): $(OBJS) + $(CC) -static $(CFLAGS) -o $(NAME) $(OBJS) -clean: - $(RM) *.o $(NAME) +clean: + $(RM) *.o $(NAME) diff --git a/chapter2/pi/fpu64/main.asm b/chapter2/pi/fpu64/main.asm index 8c32610263205e6321334003c31113ca8976e39b..2be9f725ac555eb6872b46adbb32c9c2b9b19021 100644 --- a/chapter2/pi/fpu64/main.asm +++ b/chapter2/pi/fpu64/main.asm @@ -57,7 +57,7 @@ L1: fmul st0, st0 fld1 ; st0 = 1.0 faddp st1, st0 - + ; teile 4 durch das Zwischenergebnis fdivr qword [four] @@ -72,7 +72,7 @@ L2: fld qword [sum] fmul qword [step] - ; Die ersten sechs Ganzzahlen oder Zeiger werden über die Register + ; Die ersten sechs Ganzzahlen oder Zeiger werden über die Register ; RDI, RSI, RDX, RCX, R8, and R9 übergeben. ; => siehe auch fastcall unter 32bit ; @@ -107,7 +107,7 @@ L2: ; => Wenn -- wie hier -- mit -g compiliert wird, ; sollte er wie üblich verwendet werden. mov rsp, rbp ; alter Stackframe restaurieren - pop rbp + pop rbp ; Programm verlassen & signalisieren, ; dass bei bei der Ausführung kein Fehler @@ -116,4 +116,4 @@ L2: mov rax, 93 ; Nummer des Systemaufrufs "exit" syscall ; oder auch - ; int 0x80 + ; int 0x80 diff --git a/chapter2/pi/v1/Makefile b/chapter2/pi/v1/Makefile index 409180da5e4be0df4b6f97a51891a2a8ffd32648..413b2d37a01c4297bcfd49f09093186ed9886ab6 100644 --- a/chapter2/pi/v1/Makefile +++ b/chapter2/pi/v1/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = pi_v1 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v1/main.go b/chapter2/pi/v1/main.go index a1d203b72d40a79d77c7ae6174b223973e8b004a..9bdfa422eddd1f1cbd39b9239966744daabec7c6 100644 --- a/chapter2/pi/v1/main.go +++ b/chapter2/pi/v1/main.go @@ -1,7 +1,7 @@ /* * Simple Go example, start programm with following command: * - * go run main.go + * go run main.go */ package main @@ -40,7 +40,7 @@ func main() { } elapsed := time.Since(start) - + fmt.Println("Pi : ", sum*step) fmt.Println("Time : ", elapsed) } diff --git a/chapter2/pi/v2/Makefile b/chapter2/pi/v2/Makefile index 54ba0d7eeb5207c239133e8499b2aec0c3c14c56..6aa2ee3148c4b738ab31d00de53018537e001d66 100644 --- a/chapter2/pi/v2/Makefile +++ b/chapter2/pi/v2/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = pi_v2 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v3/Makefile b/chapter2/pi/v3/Makefile index 2a26823c592139c0fabbdec3a5e5f698a6f5c549..1c65e580254499a11f2a39b364911440d8c9caaf 100644 --- a/chapter2/pi/v3/Makefile +++ b/chapter2/pi/v3/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = pi_v3 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v4/Makefile b/chapter2/pi/v4/Makefile index a581342ab3063584800e1a5c143147bd4991fa8b..e1fc43adeeabfc6cff064bed8b101571c1d51b5c 100644 --- a/chapter2/pi/v4/Makefile +++ b/chapter2/pi/v4/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = pi_v4 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v4/main.c b/chapter2/pi/v4/main.c index 280cc82039819a5882fc8021b493a24161dd8fa3..fd82bf02a3c791c4787e918d09b1a4e2a570d32b 100644 --- a/chapter2/pi/v4/main.c +++ b/chapter2/pi/v4/main.c @@ -57,7 +57,7 @@ int main(int argc, char **argv) pthread_create(&(threads[i]), NULL, thread_func, &(thr_arg[i])); } - /* Wait until all threads have terminated + /* Wait until all threads have terminated and calculate PI */ for (i = 0; i < MAX_THREADS; i++) { pthread_join(threads[i], NULL); diff --git a/chapter2/pi/v5/Makefile b/chapter2/pi/v5/Makefile index 6bec9d2e0c6d15f1c4b33b0b9fe245095c07805d..4ff25651607d60387782aa6d5dae4f693e20fa80 100644 --- a/chapter2/pi/v5/Makefile +++ b/chapter2/pi/v5/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = pi_v5 C_source = main.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v5/main.c b/chapter2/pi/v5/main.c index cceed8801c5d3f993e3998934e0fababb8a15c7a..61fdc4ba238a3cfb5e493d093e995ddb3a03da2a 100644 --- a/chapter2/pi/v5/main.c +++ b/chapter2/pi/v5/main.c @@ -58,7 +58,7 @@ int main(int argc, char **argv) pthread_create(&(threads[i]), NULL, thread_func, &(thr_arg[i])); } - /* Wait until all threads have terminated + /* Wait until all threads have terminated and calculate PI */ for (i = 0; i < MAX_THREADS; i++) { pthread_join(threads[i], NULL); diff --git a/chapter2/pi/v5/main.go b/chapter2/pi/v5/main.go index 244526ce33314122a66c312a254789434d1f392e..243c8590414e461529bd06edfbdeccd94b494032 100644 --- a/chapter2/pi/v5/main.go +++ b/chapter2/pi/v5/main.go @@ -1,7 +1,7 @@ /* * Simple Go example, start programm with following command: * - * go run main.go + * go run main.go */ package main @@ -56,7 +56,7 @@ func main() { } elapsed := time.Since(start) - + fmt.Println("Pi : ", sum*step) fmt.Println("Time : ", elapsed) } diff --git a/chapter2/pi/v6/Makefile b/chapter2/pi/v6/Makefile index 645524193435fbc95ad270280c9563a5cd509a87..b3b3aa362ccf42ffe7006bde422e7e405d0b3715 100644 --- a/chapter2/pi/v6/Makefile +++ b/chapter2/pi/v6/Makefile @@ -7,7 +7,7 @@ CXX = g++ CFLAGS = -m32 -Wall -O0 -g #CFLAGS = -m32 -Wall -O3 -g -march=native -mtune=native -mfpmath=sse,387 CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm ASMFLAGS = -f elf32 -O0 -g -F dwarf @@ -23,7 +23,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v6/calcPi_AVX.asm b/chapter2/pi/v6/calcPi_AVX.asm index d213d0d18a6cc2e42975ecdb91e7fbb3081383f2..e255ceac7f1e5b6443e8151d28ef8749ddf402ab 100644 --- a/chapter2/pi/v6/calcPi_AVX.asm +++ b/chapter2/pi/v6/calcPi_AVX.asm @@ -50,7 +50,7 @@ done: calcPi_AVX: push ebp mov ebp, esp - + push ebx push ecx @@ -88,7 +88,7 @@ L1: vaddpd ymm4, ymm4 vsubpd ymm4, ymm5 ; Die Genauigkeit ist nun 2^-23 - ; => noch eine Iteration, um eine doppelte Genauigkeit (nach IEEE) + ; => noch eine Iteration, um eine doppelte Genauigkeit (nach IEEE) ; zu erzielen. vmulpd ymm6, ymm4 vmulpd ymm6, ymm4 @@ -96,7 +96,7 @@ L1: vsubpd ymm4, ymm6 ; mit 4 multiplizieren vmulpd ymm4, ymm3 -%endif +%endif ; Summiere die ermittelten Rechteckshöhen auf vaddpd ymm0, ymm0, ymm4 ; Laufzähler erhöhen und @@ -115,4 +115,4 @@ L2: ; ebp restaurieren pop ebp - ret + ret diff --git a/chapter2/pi/v6/calcPi_FPU.asm b/chapter2/pi/v6/calcPi_FPU.asm index eb3331e0f0a7575815f39ea4328c12b165144887..76781c35babb4ac94d6cf7106fc4ae64cac60a49 100644 --- a/chapter2/pi/v6/calcPi_FPU.asm +++ b/chapter2/pi/v6/calcPi_FPU.asm @@ -33,7 +33,7 @@ L1: fmul st0, st0 fld1 ; st0 = 1.0 faddp st1, st0 - + ; teile 4 durch das Zwischenergebnis fdivr qword [four] @@ -44,11 +44,11 @@ L1: inc ecx jmp L1 L2: - + pop ecx pop ebx mov esp, ebp ; alter Stackframe restaurieren - pop ebp + pop ebp ret diff --git a/chapter2/pi/v6/calcPi_SSE.asm b/chapter2/pi/v6/calcPi_SSE.asm index 0525f469efc7b61d49ba2cb5c8d980d4d612c6fc..e94a90d5cae31896ab8ba2fb8592c46e7da9c124 100644 --- a/chapter2/pi/v6/calcPi_SSE.asm +++ b/chapter2/pi/v6/calcPi_SSE.asm @@ -41,7 +41,7 @@ done: calcPi_SSE: push ebp mov ebp, esp - + push ebx push ecx @@ -86,4 +86,4 @@ L2: ; ebp restaurieren pop ebp - ret + ret diff --git a/chapter2/pi/v6/main.c b/chapter2/pi/v6/main.c index 17e0b0477b9bff474f416ab2853d00a434efcbc2..ef384492d643f70978694ba298fd269bc2d313bf 100644 --- a/chapter2/pi/v6/main.c +++ b/chapter2/pi/v6/main.c @@ -29,7 +29,7 @@ void calcPi_intrinsic(void) __m128d xmm0 = {0.0, 0.0}; __m128d xmm1 = {step, step}; __m128d xmm2 = *((__m128d*)ofs); - __m128d xmm3, xmm4; + __m128d xmm3, xmm4; int i; for(i = 0; i < num_steps; i+=2) { diff --git a/chapter2/pi/v7/Makefile b/chapter2/pi/v7/Makefile index bae8bea88432548a21b4e228fbadf4dc22e4dcfc..09f4d70ba411e66f604bd6b937007ce6ca99d2a7 100644 --- a/chapter2/pi/v7/Makefile +++ b/chapter2/pi/v7/Makefile @@ -6,7 +6,7 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g -pthread CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm ASMFLAGS = -f elf32 -O0 -g -F dwarf @@ -22,7 +22,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter2/pi/v7/calcPi_SSE_thread.asm b/chapter2/pi/v7/calcPi_SSE_thread.asm index ddba9145e00250a5ea49c7c8f1114d0a614bec47..a794a95a7ffe46a25c533f966453bb7048aaeb50 100644 --- a/chapter2/pi/v7/calcPi_SSE_thread.asm +++ b/chapter2/pi/v7/calcPi_SSE_thread.asm @@ -45,12 +45,12 @@ L1: jmp L1 L2: ; sum = xmm0[0] + xmm0[1] - xorpd xmm3, xmm3 - xor edx, edx + xorpd xmm3, xmm3 + xor edx, edx addsd xmm3, xmm0 shufpd xmm0, xmm0, 0x1 addsd xmm3, xmm0 - + ; copy result to the memory mov edx, [ebp+16] movsd [edx], xmm3 diff --git a/chapter2/pi/v7/main.c b/chapter2/pi/v7/main.c index 4c707fc588842956d1a070e7a76d72f73dfefd8c..7a9fc8b93a79f67d329d69d98b9bf0dd68d5e60d 100644 --- a/chapter2/pi/v7/main.c +++ b/chapter2/pi/v7/main.c @@ -48,7 +48,7 @@ int main(int argc, char **argv) num_steps = 1000000; printf("\nnum_steps = %d\n", (int)num_steps); - + gettimeofday(&start, NULL); sum = 0.0; @@ -63,7 +63,7 @@ int main(int argc, char **argv) pthread_create(&(threads[i]), NULL, thread_func, &(thr_arg[i])); } - /* Wait until all threads have terminated + /* Wait until all threads have terminated and calculate sum*/ for (i = 0; i < MAX_THREADS; i++) { pthread_join(threads[i], NULL); diff --git a/chapter2/rounding_error/Makefile b/chapter2/rounding_error/Makefile index 74fd40b63a00ea8ec51b4d59e282712e1883ff3c..d80e5a200740c77c66cafd0626b568118d36dc4d 100644 --- a/chapter2/rounding_error/Makefile +++ b/chapter2/rounding_error/Makefile @@ -1,7 +1,7 @@ CC = gcc CFLAGS = -O0 -Wall -LDFLAGS = +LDFLAGS = all: main @@ -11,5 +11,5 @@ main: main.o main.o: main.c $(CC) -c $(CFLAGS) main.c -o main.o -clean: +clean: rm -f main.o main diff --git a/chapter2/rounding_error/main.c b/chapter2/rounding_error/main.c index d53a1cc4a2cc0391a8e055244822618049cafd48..1427c2925b0651a7f1092f4160bf5ac70c549a54 100644 --- a/chapter2/rounding_error/main.c +++ b/chapter2/rounding_error/main.c @@ -17,6 +17,6 @@ int main(int argc, char** argv) printf("erg2 = %.10f\n", erg2); printf("(a + b) + c = %.10f\n", (a + b) + c); printf("a + (b + c) = %.10f\n", a + (b + c)); - + return 0; } diff --git a/chapter2/strcpy/string_copy.asm b/chapter2/strcpy/string_copy.asm index 319dce107da95b1edf712fdd0f753bf5c978df9d..3b075b74f6ae3c55df5d25e51b6168d753ed9c27 100644 --- a/chapter2/strcpy/string_copy.asm +++ b/chapter2/strcpy/string_copy.asm @@ -1,14 +1,14 @@ SECTION .text global string_copy -string_copy: +string_copy: push ebp mov ebp, esp xor ecx, ecx - xor edx, edx + xor edx, edx ;aufrunf in main >> string_copy(string, "Hallo Welt"); - ; stack >> + ; stack >> ; * auf hallo welt >> ebp+12 ; * auf string >> ebp+ 8 ; RA >> ebp+ 4 @@ -16,10 +16,10 @@ string_copy: mov edi, [ebp+12] ;// neue werte mov esi, [ebp+8] ;// alte werte - -L1: + +L1: mov dl, [edi+ecx] - mov [esi+ecx], dl + mov [esi+ecx], dl cmp dl, 0 je ende inc ecx diff --git a/chapter4/aslr/Makefile b/chapter4/aslr/Makefile index 0f12ac57203b9217d53bffbc792df8caf5597005..cffc5018577a0e01f79dd39aea3ba24b252d8ae3 100644 --- a/chapter4/aslr/Makefile +++ b/chapter4/aslr/Makefile @@ -6,10 +6,10 @@ CXX = g++ # flags for debugging CFLAGS = -m32 -Wall -O0 -g CXXFLAGS = $(CFLAGS) -LDFLAGS = +LDFLAGS = RM = rm -rf ASM = nasm -ASMFLAGS = +ASMFLAGS = NAME = aslr_demo C_source = aslr_demo.c CPP_source = @@ -21,7 +21,7 @@ OBJS += $(patsubst %.asm, %.o, $(filter %.asm, $(ASM_source))) # other implicit rules %.o : %.c - $(CC) -c $(CFLAGS) -o $@ $< + $(CC) -c $(CFLAGS) -o $@ $< %.o : %.cpp $(CXX) -c $(CXXFLAGS) -o $@ $< diff --git a/chapter4/aslr/aslr_demo.c b/chapter4/aslr/aslr_demo.c index 096d716128b787d95b5653fd914a6f2d7fb90351..54db86b26bba60c3625be23ce58f476c55527cc8 100644 --- a/chapter4/aslr/aslr_demo.c +++ b/chapter4/aslr/aslr_demo.c @@ -1,8 +1,8 @@ #include <stdio.h> #include <stdlib.h> -/* - * Der Linker definiert diese Symbole, deren Adressen der Beginn +/* + * Der Linker definiert diese Symbole, deren Adressen der Beginn * des BSS- & Data-Segements repräsentieren. */ extern void __bss_start; diff --git a/chapter4/shlib/ctest.c b/chapter4/shlib/ctest.c index aad3af58c34de707e162c7938e7aac64a4dc5fae..b444abf4a3a7132de6d4d3db37caeae78ca9df5f 100644 --- a/chapter4/shlib/ctest.c +++ b/chapter4/shlib/ctest.c @@ -3,7 +3,7 @@ static void __attribute__ ((constructor)) _init(void); static void __attribute__ ((destructor)) _fini(void); - + static void _init(void) { printf("Library initialized\n"); diff --git a/chapter4/shlib/prog.c b/chapter4/shlib/prog.c index 4d7e0801a856f4fb83a22ea2a21c6a94d2d881af..1784e7dd04cd0192bca820dea3651ba9897cf382 100644 --- a/chapter4/shlib/prog.c +++ b/chapter4/shlib/prog.c @@ -4,7 +4,7 @@ #include <dlfcn.h> #include "ctest.h" -int main(int argc, char **argv) +int main(int argc, char **argv) { void *lib_handle; void (*fn)(int); @@ -12,19 +12,19 @@ int main(int argc, char **argv) /* * RTLD_LAZY: If specified, Linux is not concerned about - * unresolved symbols until they are referenced. - * RTLD_NOW: All unresolved symbols resolved when dlopen() is called. + * unresolved symbols until they are referenced. + * RTLD_NOW: All unresolved symbols resolved when dlopen() is called. * RTLD_GLOBAL: Make symbol libraries visible. */ lib_handle = dlopen("libctest.so", RTLD_LAZY); - if (!lib_handle) + if (!lib_handle) { fprintf(stderr, "%s\n", dlerror()); exit(1); } fn = dlsym(lib_handle, "ctest1"); - if ((error = dlerror()) != NULL) + if ((error = dlerror()) != NULL) { fprintf(stderr, "%s\n", error); exit(1);