diff --git a/Makefile b/Makefile index 2584e4a..5168403 100644 --- a/Makefile +++ b/Makefile @@ -87,7 +87,7 @@ $U/initcode: $U/initcode.S tags: $(OBJS) _init etags *.S *.c -ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o +ULIB = $U/ulib.o $U/usys.o $U/printf.o $U/umalloc.o $U/array.o _%: %.o $(ULIB) $(LD) $(LDFLAGS) -T $U/user.ld -o $@ $^ @@ -103,7 +103,7 @@ $U/usys.o : $U/usys.S $U/_forktest: $U/forktest.o $(ULIB) # forktest has less library code linked in - needs to be small # in order to be able to max out the proc table. - $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/ulib.o $U/usys.o $U/umalloc.o $U/printf.o + $(LD) $(LDFLAGS) -N -e main -Ttext 0 -o $U/_forktest $U/forktest.o $U/printf.o $U/umalloc.o $U/array.o $U/ulib.o $U/usys.o $(OBJDUMP) -S $U/_forktest > $U/forktest.asm mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h @@ -116,6 +116,7 @@ mkfs/mkfs: mkfs/mkfs.c $K/fs.h $K/param.h .PRECIOUS: %.o UPROGS=\ + $U/_arraytests\ $U/_cat\ $U/_echo\ $U/_forktest\ diff --git a/user/a.out b/user/a.out new file mode 100755 index 0000000..1ca5f21 Binary files /dev/null and b/user/a.out differ diff --git a/user/array.c b/user/array.c new file mode 100644 index 0000000..41257f2 --- /dev/null +++ b/user/array.c @@ -0,0 +1,104 @@ +#include "kernel/types.h" +#include "kernel/stat.h" +#include "kernel/fcntl.h" +#include "user/user.h" + +// +// wrapper so that it's OK if main() does not call exit(). +// + + +/* +*reverses the values of an array of any type in java +*/ +void +reverseArray(int* arr, uint64 size){ + int start = 0; + int end = size - 1; + + //switches the values at opposite ends until indexes start and end meet + while(start < end){ + int temp = arr[start]; + arr[start++] = arr[end]; + arr[end--] = temp; + } +} + +/* +*helper method used to swap elements +*/ +void +swap(int *arr, uint64 a, uint64 b){ + int temp = arr[a]; + arr[a] = arr[b]; + arr[b] = temp; +} + +/* +*splits the integer array in subarrays that will be sorted +*/ +uint64 +partition(int *arr, uint64 low, uint64 high){ + int pivot = arr[high];// makes the last element the pivot + uint64 i = low - 1; //index of the smaller element + + for(uint64 j = low; j < high; j++){ + //if current element is smaller than or equal to pivot + //it goes on the left side of the sub array + if(arr[j] <= pivot){ + i++; + //swap is performed between the indexs + swap(arr, j, i); + } + } + //pivot is in it's correct position + swap(arr, i + 1, high); + return i + 1; //returns the partition index +} + +/* +*recursively sorts the elements using quick sort algorithm +*/ +void +sort(int* arr, uint64 low, uint64 high){ + if(low < high){ + uint64 pt_index = partition(arr, low, high); + + sort(arr, low, pt_index - 1); + sort(arr, pt_index + 1, high); + } + +} + +/* +*gets the max value of an integer array +*/ +int +getMax(int* arr, uint size){ + int max = -2147483648; + + //loops through whole array and find the max + for(uint64 i = 0; i < size - 1; i++){ + if(arr[i] > max){ + max = arr[i]; + } + } + + return max; +} + +/* +*gets the smallest intefer value inside an array +*/ +int +getMin(int* arr, uint64 size){ + int min = 2147483647; + + //loops through the whole array and finds min + for(uint64 i = 0; i < size - 1; i++){ + if(arr[i] < min){ + min = arr[i]; + } + } + return min; +} diff --git a/user/array.h b/user/array.h new file mode 100644 index 0000000..6e5a390 --- /dev/null +++ b/user/array.h @@ -0,0 +1,13 @@ +//array.c +//reverse the values of an integer array in java +void reverseArray(int*, uint64); +//sorts in integer array using quicksort +void sort(int*, uint64, uint64); +//swap method using to swap values in quicksort algorithm +void swap(int*, uint64, uint64); +//parttitions the array on integers into sub arrays +uint64 partition(int*, uint64, uint64); +//get's the max element of an array +int getMax(int*, uint64); +//gets the min element of an array +int getMin(int*, uint64); diff --git a/user/arraytests.c b/user/arraytests.c new file mode 100644 index 0000000..257ab94 --- /dev/null +++ b/user/arraytests.c @@ -0,0 +1,49 @@ +#include "kernel/types.h" +#include "user/user.h" +#include "kernel/fcntl.h" +#include "user/array.h" + +int +main(void){ + int arr[10] = {5, -4, 2, 22, 12, -56, 3, 8, 34, 2}; + + uint64 size = sizeof(arr) / sizeof(arr[0]); + printf("size: %d\n", size); + + printf("Array before: "); + for(int i = 0; i < size; i++){ + printf("%d ", arr[i]); + } + + printf("\n"); + + reverseArray(arr, size); + + printf("Array in reverse: "); + + for(int i = 0; i < size ; i++){ + printf("%d ", arr[i]); + } + + printf("\n"); + + uint64 min = getMin(arr, size); + printf("Get min value: "); + printf("%d \n", min); + + uint64 max = getMax(arr, size); + printf("Get max value: "); + printf("%d \n", max); + + sort(arr, 0, size - 1); + + printf("sorted array: "); + for(int i = 0; i < size; i++){ + printf("%d ", arr[i]); + } + + + + return 0; +} + diff --git a/user/mittens.c b/user/mittens.c new file mode 100644 index 0000000..519dbcf --- /dev/null +++ b/user/mittens.c @@ -0,0 +1,40 @@ +#include +int +main(void){ + + + //created everything by myself + printf("\t\t_____ _____\n"); + printf("\t\t##--## ##--##\n"); + printf("\t\t##---## ##---##\n"); + printf("\t\t##----## ##----##\n"); + printf("\t\t##-----## ##-----##\n"); + printf("\t\t##------## ##------##\n"); + printf("\t\t##########################################\n"); + printf("\t\t##......................|#################\n"); + printf("\t\t##......................|#################\n"); + printf("\t\t##.._________...........|####--------#####\n"); + printf("\t\t##..| __ |...........|###| __ |####\n"); + printf("\t\t##..| (__) |...........|###| (__) |####\n"); + printf("\t\t##..|_______|...........|###|________|####\n"); + printf("\t\t##......................|#################\n"); + printf("\t\t##......................|---------------##\n"); + printf("\t\t##......................................##\n"); + printf("\t\t##.........------#######------..........##\n"); + printf("\t\t##.........-------#####-------..........##\n"); + printf("\t####### ##.........--------###--------..........## #######\n"); + printf("\t####### ##..................|...................## #######\n"); + printf("\t####### ##..............\\../.\\../...............## #######\n"); + printf("\t####### ##...............\\/...\\/................## #######\n"); + printf("\t####### ##......................................## #######\n"); + printf("\t####### ########################################## #######\n\n"); + printf(" ###### #### ## ## \t\t######## #### ###### ###### ## ## #### ######## ######\n"); + printf("## ## ## ### ## \t\t## ## ## ## ## ## ## ## ## ## ## ## ##\n"); + printf("## ## #### ## \t\t## ## ## ## ## ## ## ## ## ## \n"); + printf(" ###### ## ## ## ## \t\t######## ## ###### ## ## ## ## ## ###### \n"); + printf(" ## ## ## #### \t\t## ## ## ## ## ## ## ## ## ##\n"); + printf("## ## ## ## ### \t\t## ## ## ## ## ## ## ## ## ## ## ## ##\n"); + printf(" ###### #### ## ## \t\t######## #### ###### ###### ####### #### ## ###### \n"); + + return 0; +} diff --git a/user/vagabound.c b/user/vagabound.c new file mode 100644 index 0000000..4d03d6f --- /dev/null +++ b/user/vagabound.c @@ -0,0 +1,49 @@ +#include + +int +main(void){ + //created the title and the quote myself, and the art was pulled from onine + printf("## ## ### ###### ### ######## ####### ## ## ## ## ########\n"); + printf("## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ## ##\n"); + printf("## ## ## ## ## ## ## ## ## ## ## ## ## #### ## ## ##\n"); + printf("## ## ## ## ## #### ## ## ######## ## ## ## ## ## ## ## ## ##\n"); + printf(" ## ## ######### ## ## ######### ## ## ## ## ## ## ## #### ## ##\n"); + printf(" ## ## ## ## ## ## ## ## ## ## ## ## ## ## ## ### ## ##\n"); + printf(" ### ## ## ###### ## ## ######## ####### ####### ## ## ########\n\n"); + printf(" A river cuts through rock, not beacuse of its power, but because of its persistence\n\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⠋⡴⠫⠉⠀⡴⠦⠌⠛⠿⠟⠛⣯⣻⣿⣻⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣏⠀⢁⠀⠀⠀⠀⠀⠀⠀⠓⠚⠛⠟⢙⣩⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣟⠀⠀⠀⠀⠀⠀⠀⠀⢠⣤⣹⡿⣿⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠛⠛⠻⠟⠛⠻⣻⢿⡟⠐⠀⠀⠀⠀⠀⠀⠁⠈⠛⡫⠵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡟⠁⠀⠀⠀⠀⠀⠀⠀⠁⠂⠘⠀⠀⠀⠀⠀⠀⠀⠀⠀⠁⠒⢠⣵⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣾⣿⣿⡿⠛⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⣿⣄⡀⠀⠶⣤⡄⠀⣶⣿⣿⡇⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣇⣿⣿⠃⡐⠀⠀⠀⠀⠀⠀⠀⠀⠄⠀⠀⠀⡀⠀⠈⣟⡟⠀⣶⣶⣖⣤⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⡿⣻⣿⣬⠉⠐⠀⠀⠀⠀⠠⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⠸⠥⢾⣿⣾⡟⣿⣸⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣷⣼⢿⣿⠀⠀⠀⠀⠀⠠⠀⠐⠈⠄⠂⠀⠐⠠⡄⠄⠀⠀⠀⠈⡉⣡⡨⠍⠻⢛⢽⣶⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣶⠆⣤⣰⡌⢿⣆⠀⠀⠀⠀⠀⠀⠀⠐⠛⠢⠀⠀⠀⠀⠀⠉⠈⠠⣼⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⠁⠙⢀⣴⠨⣛⡆⢣⡤⣄⠀⠀⠈⠁⠀⠐⠘⢂⠀⠀⠀⠀⠈⠲⡌⡚⢻⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢨⣲⠺⠋⠀⠻⢧⣹⣷⣗⢳⡄⠀⢨⠓⠃⡠⠔⢁⡀⠀⠀⠀⠀⢀⢻⡑⠹⣿⣽⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⣿⣿⡟⣙⡿⢿⣿⣿⣿⡸⡇⢒⣬⣾⣾⣣⣷⣻⣿⣎⢿⡄⠀⠁⢛⡃⠀⠩⠀⠀⠀⠀⠀⠈⢹⣿⣷⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⡿⠫⠴⠚⡴⡆⢿⣿⣿⡏⡇⡿⡋⠿⠛⣙⣿⣗⣼⣿⣭⡑⠀⠊⠘⠇⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⢻⣻⣿⣿⣿⣿⣿⣿⣿\n"); + printf("⣿⠿⢹⢱⢿⣿⣿⣿⣿⣿⣿⣏⣿⣇⣿⣈⠉⠹⠉⢹⣿⣿⠿⠀⢀⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢿⣿⣿⣿⠏⣹⡿⢿⣹⣿⣿⣿⣿\n"); + printf("⣿⡪⠀⡿⠎⣕⡘⡄⣸⡿⣿⣿⣿⣿⣿⣿⣦⣐⢻⠦⠘⡛⠈⣀⠀⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠻⣿⣿⣤⠋⠊⢀⠜⡗⣻⣿⣿\n"); + printf("⡏⢹⢣⢱⣾⣿⡏⣭⠁⡟⢻⣿⣿⣿⣿⣿⣿⣿⣇⡀⠀⣀⣾⣿⡇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡙⠨⠷⡄⠻⢠⣺⠿⡟⢻\n"); + printf("⣿⡀⣿⣯⡟⠹⣍⢉⢨⣎⢸⣿⣿⣿⣿⣿⣿⣿⣿⣷⣿⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣖⠂⠀⠀⢌⠀⡋⢀⣺\n"); + printf("⡏⡧⣿⡄⢻⡘⣇⠨⢘⡻⠁⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⡿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⡟⠠⠁⢸⡆⣬⣿⣿\n"); + printf("⣷⢷⢿⣿⣾⢷⣥⠀⠶⠬⣰⣿⣿⣿⣿⣿⣿⣿⣿⣿⣿⢋⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣁⣼⠐⣿⢿⣿\n"); + printf("⣿⡌⠛⢿⣿⡏⣿⣄⠀⢀⣿⣿⣿⣿⣿⣿⣿⡿⣿⡟⣱⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠌⣹⡎⢸⣧⠻\n"); + printf("⣿⣷⣀⣆⣹⡿⢹⣷⣾⢸⣿⣿⣿⣿⣿⣿⢡⣼⠀⢰⡟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣄⡟⣿⢸⢿⡥\n"); + printf("⣿⣿⣿⠃⣿⣇⣺⣿⣿⡅⣿⣿⣿⣿⣿⠃⢈⡴⠃⡈⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⡁⠘⡏⣼⡟\n"); + printf("⣿⣿⡿⣔⣿⠹⣿⣿⣿⡥⣻⣿⣿⣿⣿⣤⠟⣴⡇⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢰⠄⢹⣧⣻⣷\n"); + printf("⣿⣿⡿⢿⣸⣿⣿⢿⣿⠀⢇⠛⠛⠿⣿⡇⠘⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⠄⠸⡟⣿⢿\n"); + printf("⣿⣿⠇⢸⡟⣿⣿⡟⣼⣧⠂⠀⠀⠀⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢨⡦⠑⣽⣿⣿\n"); + printf("⣿⡏⠀⠀⠷⣿⣿⣟⣈⠟⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢸⣍⣻⡼⣿⣿\n"); + printf("⣿⣧⠀⠀⠀⢻⣿⣿⠇⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠸⣾⣿⣿⣿⣿\n"); + printf("⣿⣿⠀⠀⠀⠘⠏⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⡽⣽⢿⣿⣿⣿\n"); + return 0; +} + + + + +