Skip to content
Snippets Groups Projects
Verified Commit bb52e634 authored by abrahas55's avatar abrahas55
Browse files

added asm-example branch for CA

parent 842f1e2b
No related branches found
No related tags found
No related merge requests found
NASM=nasm
NASMFLAGS=-f elf64
CC = gcc 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 #CPPFLAGS = -MMD -MF $*.d #activate only if you want extra output as .d files
# TODO: edit BIN with your target binary (e.g. exercise01) # TODO: edit BIN with your target binary (e.g. exercise01)
BIN = example BIN = example
OBJS = $(BIN).o OBJS = $(BIN).o wrapper.o
all: $(BIN) all: $(BIN)
$(BIN): $(OBJS)
# uncomment this if you want object files %: %.o
#$(BIN): $(OBJS) $(CC) -o $@ $(LDFLAGS) $^ $(LDLIBS)
%.o: %.asm
$(NASM) -o $@ $(NASMFLAGS) $<
%.o: %.c
$(CC) -c -o $@ $(CPPFLAGS) $(CFLAGS) $<
run: $(BIN) run: $(BIN)
./$(BIN) ./$(BIN)
# define test cases here # TODO: define test cases here
test1: $(BIN) test1: $(BIN)
./$(BIN) 5 ./$(BIN) 5
test2: $(BIN) test2: $(BIN)
......
# ALP4 repository template -- C # ALP4 repository template -- ASM
Use this template for the ALP4 course. This branch should be used for C This branch should be used for ASM exercises (not relevant to ALP4).
exercises.
## How to build ## How to build
...@@ -9,14 +8,17 @@ This example uses Make, see the ...@@ -9,14 +8,17 @@ This example uses Make, see the
[documentation](https://www.gnu.org/software/make/manual/make.html) [documentation](https://www.gnu.org/software/make/manual/make.html)
for more information on how to use it. 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 ## Submission
exercise.
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 ## Contributions
Feel free to open issues or submit merge requests for changes. Also you could Feel free to open issues or submit merge requests for changes.
fork this to prepare templates for other courses.
/*
* 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;;
}
#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;
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment