Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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 $@ $^
Expand All @@ -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
Expand All @@ -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\
Expand Down
Binary file added user/a.out
Binary file not shown.
104 changes: 104 additions & 0 deletions user/array.c
Original file line number Diff line number Diff line change
@@ -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;
}
13 changes: 13 additions & 0 deletions user/array.h
Original file line number Diff line number Diff line change
@@ -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);
49 changes: 49 additions & 0 deletions user/arraytests.c
Original file line number Diff line number Diff line change
@@ -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;
}

40 changes: 40 additions & 0 deletions user/mittens.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#include <stdio.h>
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;
}
49 changes: 49 additions & 0 deletions user/vagabound.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#include <stdio.h>

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;
}