diff --git a/Makefile b/Makefile index a7bb27ec88f24b34fa793b2ad76b27901856e138..73c05cca8e757a6968901af8ccbebb41866496b1 100644 --- a/Makefile +++ b/Makefile @@ -1,19 +1,27 @@ +NASM=nasm +NASMFLAGS=-f elf64 CC = gcc -CFLAGS = -std=c11 -Wall -Wextra -pedantic -O2 -g -pthread +CFLAGS = -std=c11 -Wall -Wextra -pedantic -O2 -g #CPPFLAGS = -MMD -MF $*.d #activate only if you want extra output as .d files # TODO: edit BIN with your target binary (e.g. exercise01) -BIN = example -OBJS = $(BIN).o +BIN = example +OBJS = $(BIN).o wrapper.o all: $(BIN) +$(BIN): $(OBJS) -# uncomment this if you want object files -#$(BIN): $(OBJS) +%: %.o + $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS) + +%.o: %.asm + $(NASM) -o $@ $(NASMFLAGS) $< +%.o: %.c + $(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $< run: $(BIN) ./$(BIN) -# define test cases here +# TODO: define test cases here test1: $(BIN) ./$(BIN) 5 test2: $(BIN) diff --git a/README.md b/README.md index def464eb6d04417a38930ab21088593b541377d4..bb5174f126034624127ab815fd833d5bc2f926e2 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ -# ALP4 repository template -- C +# ALP4 repository template -- ASM -Use this template for the ALP4 course. This branch should be used for C -exercises. +This branch should be used for ASM exercises (not relevant to ALP4). ## How to build @@ -9,14 +8,17 @@ This example uses Make, see the [documentation](https://www.gnu.org/software/make/manual/make.html) for more information on how to use it. -## Submission +### Makefile + +Edit the Makefile according to your exercise, correct the name for your binary +and the wrapper (or rename the given wrapper file to wrapper.c). +Also don't forget to add test cases. -In Whiteboard, add the corresponding commit hash in the comment field of the -exercise. +## Submission -Keep in mind this is specific to the course in Summer 2022! +Submit everything in this repo, you are also welcome to submit pdf's in +whiteboard. ## Contributions -Feel free to open issues or submit merge requests for changes. Also you could -fork this to prepare templates for other courses. +Feel free to open issues or submit merge requests for changes. diff --git a/example.c b/example.c deleted file mode 100644 index 372643f959203da4c8fac41bcf8c6e593570ca76..0000000000000000000000000000000000000000 --- a/example.c +++ /dev/null @@ -1,52 +0,0 @@ -/* - * small example showing how to use pthreads - * - * will print output until user ends program with either Ctrl-C - * - * for more information check out 'man 7 pthreads' and corresponding manpages - * from chapter 3 -*/ - -#include <stdlib.h> -#include <stdio.h> -#include <unistd.h> -#include <inttypes.h> -#include <pthread.h> - -void *start_routine(void *arg) { - (void) arg; - pthread_t pid = pthread_self(); - for(size_t i = 0; i < 50; i++) { - printf("i am thread %lu\n", pid); - sleep(1); - } - pthread_exit(EXIT_SUCCESS); -} - -int main(int argc, char const *argv[]) { - (void) argc; - (void) argv; - - // ignore this, just to suppress warnings - long unsigned int thread_ids[6]; - - size_t amount_threads = 5; - - for(size_t i = 0; i < amount_threads; i++) { - // we do no error checking! - pthread_create( - &thread_ids[i], - NULL, // default attributes - &start_routine, // what should the thread do - NULL // no arguments for the thread - ); - } - - // either do this for lazy or join the threads together - while(1) { - puts("main!"); - sleep(1); - } - - return EXIT_SUCCESS;; -} diff --git a/wrapper.c b/wrapper.c new file mode 100644 index 0000000000000000000000000000000000000000..4b0fcd8f4d70a686963d45fc73870351acad3b99 --- /dev/null +++ b/wrapper.c @@ -0,0 +1,25 @@ +#include <stdio.h> +#include <stdlib.h> +#include <stdbool.h> +#include <inttypes.h> + +extern uint64_t collatz(uint64_t); + +int main(int argc, char* argv[]) { + if(argc < 2) { + fputs("Not enough arguments!\n", stderr); + return EXIT_FAILURE; + } + + char* test = NULL; + uint64_t val = strtoull(argv[1], &test, 10); + if(*test) { + fprintf(stderr,"Invalid Argument: %s\n", argv[1]); + return EXIT_FAILURE; + } + + uint64_t res = collatz(val); + printf("collatz(%"PRIu64") = %"PRIu64"\n", val, res); + + return EXIT_SUCCESS; +}