From c1803336d1f1db722f76856d8395beef6b2688b0 Mon Sep 17 00:00:00 2001 From: Johannes Vollmer Date: Sat, 10 Oct 2015 14:02:49 +0200 Subject: [PATCH 1/4] edited AUTHORS --- AUTHORS | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/AUTHORS b/AUTHORS index f8c27e6..b024818 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,5 +1,2 @@ -Martin Aigner -Christian Barthel -Christoph Kirsch -Michael Lippautz -Simone Oblasser \ No newline at end of file +Tobias Seiler +Johannes Vollmer \ No newline at end of file From 198255d91edd886367d2d740b3f1a9343cf9db92 Mon Sep 17 00:00:00 2001 From: Johannes Vollmer Date: Thu, 15 Oct 2015 19:53:31 +0200 Subject: [PATCH 2/4] fulfilled assignment0: added a linked list --- selfie.c | 201 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 201 insertions(+) diff --git a/selfie.c b/selfie.c index c2b5d87..e9e0d56 100755 --- a/selfie.c +++ b/selfie.c @@ -4104,6 +4104,207 @@ int* copyC2CStarArguments(int argc, int *argv) { return cstar_argv; } +///////////////////////////////////////////////////////////////////// +//////------Assignment 0: Implementation of a Linked List------////// +///////////////////////////////////////////////////////////////////// + +// Initialization of the linked list (Creating the header with data -1) +// The header cannot be deleted!! +int* initializeList(int *list) { + int *header; + int data = -1; // no data inserted + + header = malloc(4*2); + *header = 0; + *(header+1) = data; + return header; +} + +// Add a node to the linked list at the bottom +int* addToList(int *list, int data) { + + int *newNode; + newNode = malloc(4*2); + *newNode = list; + *(newNode+1) = data; + return newNode; +} + +// Iterate through the linked list and get the nth node of the list +int* getNodeFromList(int* list, int nthNode) { + + while(nthNode > 0) { + list = *list; + nthNode = nthNode - 1; + } + + return list; +} + +// Iterate through the linked list and get the data of the nth node of the list +int getDataFromList(int* list, int nthNode) { + + while(nthNode > 0) { + list = *list; + nthNode = nthNode - 1; + } + + return *(list+1); +} + +// Iterate through the linked list and set the data of the nth node of the list +int alterDataInList(int* list, int nthNode, int newValue) { + + while(nthNode > 0) { + list = *list; + nthNode = nthNode - 1; + } + + *(list+1) = newValue; + + return *(list+1); +} + + +// Get the size of the linked list +int sizeOfList(int* list) { + + int *count; + count = malloc(4); + *count = 0; + + while(*list != 0) { + list = *list; + *count = *count + 1; + } + return *count; +} + +// Delete a node from the linked list from the top +int* deleteFirstNodeFromList(int* list) { + + int *prev; + int *next; + prev = malloc(2*4); + next = malloc(2*4); + *prev = 0; + *next = 0; + int size = sizeOfList(list); + + prev = getNodeFromList(list, size-2); + next = getNodeFromList(list, size); + *prev = next; + + return list; +} + +// Sort the list with Bubble Sort +int* sortList(int* list) { + + int size = sizeOfList(list); + while(size > 1){ + int i = 0; + while(i= 0) { + int number = getDataFromList(list, *counter); + int *Buffer = (int*)malloc(4*10); + print(itoa( number, Buffer, 10, 0)); + putchar(CHAR_LF); + *counter = *counter - 1; + } + +} + +int testList() { + + int *list; + // Create new linked list (FIFO Linked List): + // top -> [9,7,8,2,4,1,5,3] -> bottom + printString('I','n','s','e','r','t',' ','i','n','t','o',' ','l','i','s','t',CHAR_LF,0,0,0); + list = initializeList(list); + list = addToList(list, 9); + list = addToList(list, 7); + list = addToList(list, 8); + list = addToList(list, 2); + list = addToList(list, 4); + list = addToList(list, 1); + list = addToList(list, 5); + list = addToList(list, 3); + printList(list); + + // Delete the first node (FIFO Linked List): + // top -> [2,4,1,5,3] -> bottom + printString('D','e','l','e','t','e',' ','f','i','r','s','t',' ','n','o','d','e',CHAR_LF,0,0); + list = deleteFirstNodeFromList(list); + list = deleteFirstNodeFromList(list); + list = deleteFirstNodeFromList(list); + printList(list); + + // Sorting the list + // top -> [5,4,3,2,1] -> bottom + printString('S','o','r','t','i','n','g',' ','t','h','e',' ','l','i','s','t',CHAR_LF,0,0,0); + list = sortList(list); + printList(list); + + exit(0); +} + +int main(int argc, int *argv) { + int *cstar_argv; + int *firstParameter; + + initLibrary(); + + initRegister(); + initDecoder(); + initSyscalls(); + + cstar_argv = copyC2CStarArguments(argc, argv); + + if (argc > 1) { + firstParameter = (int*) (*(cstar_argv+1)); + + if (*firstParameter == '-') { + if (*(firstParameter+1) == 'c') + main_compiler(); + else if (*(firstParameter+1) == 'm') { + if (argc > 3) + main_emulator(argc, argv, cstar_argv); + else + exit(-1); + } + else { + exit(-1); + } + } else { + exit(-1); + } + } else + // default: compiler + //main_compiler(); + testList(); +} + int main(int argc, int *argv) { int *cstar_argv; int *firstParameter; From 41708c6fdcd27c0b23e06c72356dda2b9a95128b Mon Sep 17 00:00:00 2001 From: Johannes Vollmer Date: Thu, 15 Oct 2015 22:19:53 +0200 Subject: [PATCH 3/4] deleted redundand "main" --- selfie.c | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) diff --git a/selfie.c b/selfie.c index e9e0d56..1b2362e 100755 --- a/selfie.c +++ b/selfie.c @@ -4303,39 +4303,4 @@ int main(int argc, int *argv) { // default: compiler //main_compiler(); testList(); -} - -int main(int argc, int *argv) { - int *cstar_argv; - int *firstParameter; - - initLibrary(); - - initRegister(); - initDecoder(); - initSyscalls(); - - cstar_argv = copyC2CStarArguments(argc, argv); - - if (argc > 1) { - firstParameter = (int*) (*(cstar_argv+1)); - - if (*firstParameter == '-') { - if (*(firstParameter+1) == 'c') - main_compiler(); - else if (*(firstParameter+1) == 'm') { - if (argc > 3) - main_emulator(argc, argv, cstar_argv); - else - exit(-1); - } - else { - exit(-1); - } - } else { - exit(-1); - } - } else - // default: compiler - main_compiler(); -} +} \ No newline at end of file From 267106c11187f023702ee5914b81eebcf2d6bf3b Mon Sep 17 00:00:00 2001 From: Johannes Vollmer Date: Mon, 19 Oct 2015 13:57:37 +0200 Subject: [PATCH 4/4] - fixed AUTHORS --- AUTHORS | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/AUTHORS b/AUTHORS index b024818..7d19ede 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,2 +1,7 @@ +Martin Aigner +Christian Barthel +Christoph Kirsch +Michael Lippautz +Simone Oblasser Tobias Seiler Johannes Vollmer \ No newline at end of file