From f0f1892c8c566e741eb0ff4b6af2be7593c3dbef Mon Sep 17 00:00:00 2001 From: "Elf M. Sternberg" Date: Mon, 30 Apr 2018 07:38:44 -0700 Subject: [PATCH] Re-organized the files for readability. --- Makefile | 31 ++++-------------- number.s => incomplete/number.s | 0 something.s => incomplete/something.s | 0 .../threads-x86_64.s | 0 makefiles/help.make | 4 +++ x86/Makefile | 31 ++++++++++++++++++ hello32.s => x86/hello.s | 0 counted-hello32.s => x86/strlen.s | 0 subroutine-hello32.s => x86/subroutines.s | 0 x86_64/Makefile | 32 +++++++++++++++++++ hello64.s => x86_64/hello.s | 0 counted-hello64.s => x86_64/strlen.s | 0 subroutine-hello64.s => x86_64/subroutines.s | 0 13 files changed, 74 insertions(+), 24 deletions(-) rename number.s => incomplete/number.s (100%) rename something.s => incomplete/something.s (100%) rename threads-x86_64.s => incomplete/threads-x86_64.s (100%) create mode 100644 makefiles/help.make create mode 100644 x86/Makefile rename hello32.s => x86/hello.s (100%) rename counted-hello32.s => x86/strlen.s (100%) rename subroutine-hello32.s => x86/subroutines.s (100%) create mode 100644 x86_64/Makefile rename hello64.s => x86_64/hello.s (100%) rename counted-hello64.s => x86_64/strlen.s (100%) rename subroutine-hello64.s => x86_64/subroutines.s (100%) diff --git a/Makefile b/Makefile index 8804791..7a7f0d8 100644 --- a/Makefile +++ b/Makefile @@ -7,29 +7,12 @@ help: ## Print this help message sort -nr | head -1) && \ perl -ne "m/^((\w|-)*):.*##\s*(.*)/ && print(sprintf(\"%s: %s\t%s\n\", \$$1, \" \"x($$M-length(\$$1)), \$$3))" Makefile -hello32: hello32.s ## Build the 32 bit version of Project 2 - nasm -f elf hello32.s - ld -m elf_i386 -o hello32 hello32.o - -hello64: hello64.s ## Build the 32 bit version of Project 2 - nasm -f elf64 hello64.s - ld -o hello64 hello64.o - -counted-hello32: counted-hello32.s ## Build the 32 bit version of Project 3 - nasm -f elf counted-hello32.s - ld -m elf_i386 -o counted-hello32 counted-hello32.o - -counted-hello64: counted-hello64.s ## Build the 32 bit version of Project 3 - nasm -f elf64 counted-hello64.s - ld -o counted-hello64 counted-hello64.o - -subroutine-hello32: subroutine-hello32.s ## Build the 32 bit version of Project 3 - nasm -f elf subroutine-hello32.s - ld -m elf_i386 -o subroutine-hello32 subroutine-hello32.o - -subroutine-hello64: subroutine-hello64.s ## Build the 32 bit version of Project 3 - nasm -f elf64 subroutine-hello64.s - ld -o subroutine-hello64 subroutine-hello64.o +all: ## Make everything in all trees + cd x86 && make all + cd x86_64 && make all clean: ## Delete all built and intermediate features - rm -f hello32 hello64 counted-hello32 counted-hello64 *.o + cd x86 && make clean + cd x86_64 && make clean + +include ./makefiles/help.make diff --git a/number.s b/incomplete/number.s similarity index 100% rename from number.s rename to incomplete/number.s diff --git a/something.s b/incomplete/something.s similarity index 100% rename from something.s rename to incomplete/something.s diff --git a/threads-x86_64.s b/incomplete/threads-x86_64.s similarity index 100% rename from threads-x86_64.s rename to incomplete/threads-x86_64.s diff --git a/makefiles/help.make b/makefiles/help.make new file mode 100644 index 0000000..26a8c7e --- /dev/null +++ b/makefiles/help.make @@ -0,0 +1,4 @@ +run-help: ## Print this help message + @M=$$(perl -ne 'm/^((\w|-)*):.*##/ && print length($$1)."\n"' Makefile | \ + sort -nr | head -1) && \ + perl -ne "m/^((\w|-)*):.*##\s*(.*)/ && print(sprintf(\"%s: %s\t%s\n\", \$$1, \" \"x($$M-length(\$$1)), \$$3))" Makefile diff --git a/x86/Makefile b/x86/Makefile new file mode 100644 index 0000000..5b62d27 --- /dev/null +++ b/x86/Makefile @@ -0,0 +1,31 @@ +NASM=nasm +LD=ld +COMPILE_32=elf + +# LD often has several different linking modes. This sets the mode +# explicitly, but if you're running on 32-bit Linux LD will use this +# mode by default and the '-m' argument is unnecessary. +LINK_32=elf_i386 + +default: help + +all: hello strlen subroutines ## Build everything at once + +%.o: %.s + $(NASM) -f $(COMPILE_32) $< + +hello: hello.o ## Build Lesson 2: Print string with known length, exit cleanly + $(LD) -m $(LINK_32) -o $@ $< + +strlen: strlen.o ## Build Lesson 2: Determine length programmatically + $(LD) -m $(LINK_32) -o $@ $< + +subroutines: subroutines.o ## Build Lesson 3: Separate strlen() and puts() into subroutine. + $(LD) -m $(LINK_32) -o $@ $< + +help: run-help ## Print this helpful message (default) + +clean: + rm -f hello strlen subroutines *.o + +include ../makefiles/help.make diff --git a/hello32.s b/x86/hello.s similarity index 100% rename from hello32.s rename to x86/hello.s diff --git a/counted-hello32.s b/x86/strlen.s similarity index 100% rename from counted-hello32.s rename to x86/strlen.s diff --git a/subroutine-hello32.s b/x86/subroutines.s similarity index 100% rename from subroutine-hello32.s rename to x86/subroutines.s diff --git a/x86_64/Makefile b/x86_64/Makefile new file mode 100644 index 0000000..e2444b5 --- /dev/null +++ b/x86_64/Makefile @@ -0,0 +1,32 @@ +NASM=nasm +LD=ld +COMPILE_64=elf64 + +# LD often has several different linking modes. This sets the mode +# explicitly, but if you're running on 64-bit Linux LD will use this +# mode by default and the '-m' argument is unnecessary. +LINK_64=elf_x86_64 + +default: help + +all: hello strlen subroutines ## Build everything at once + +%.o: %.s + $(NASM) -f $(COMPILE_64) $< + +hello: hello.o ## Build Lesson 2: Print string with known length, exit cleanly + $(LD) -m $(LINK_64) -o $@ $< + +strlen: strlen.o ## Build Lesson 2: Determine length programmatically + $(LD) -m $(LINK_64) -o $@ $< + +subroutines: subroutines.o ## Build Lesson 3: Separate strlen() and puts() into subroutine. + $(LD) -m $(LINK_64) -o $@ $< + +help: run-help ## Print this helpful message (default) + +clean: + rm -f hello strlen subroutines *.o + +include ../makefiles/help.make + diff --git a/hello64.s b/x86_64/hello.s similarity index 100% rename from hello64.s rename to x86_64/hello.s diff --git a/counted-hello64.s b/x86_64/strlen.s similarity index 100% rename from counted-hello64.s rename to x86_64/strlen.s diff --git a/subroutine-hello64.s b/x86_64/subroutines.s similarity index 100% rename from subroutine-hello64.s rename to x86_64/subroutines.s