-
Notifications
You must be signed in to change notification settings - Fork 5
Selfie master #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
mistay
wants to merge
10
commits into
cksystemsteaching:selfie-master
Choose a base branch
from
mistay:selfie-master
base: selfie-master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
51bb0c6
AUTHORS: added armin langhofer as an author
640920f
assignment 0: readme for instructions how to compile and run, impl in…
c11de3c
Merge remote-tracking branch 'upstream/selfie-master' into selfie-master
ffb9d14
assignment1
ed7a1f3
demo code and docs
fa3373e
merge
38cd49e
assignment2: implemented segmenttable, sched_yield() and demo for coo…
7fbc692
assignment3: implemented kernel process running on top of emulator
fed97f7
assignment4: mutex
64d74e0
assignment5: virtual memory
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| ######################################### | ||
| ## Assignment 0: Basic data structures ## | ||
| ######################################### | ||
| https://github.com/cksystemsteaching/AOS-Winter-2015 | ||
| Author: armin langhofer <uni@langhofer.at> | ||
|
|
||
| This is my implementation of a linked list in C*. | ||
|
|
||
| To Compile, please follow these steps: | ||
| ====================================== | ||
| 1. install ubuntu 32bit lts server edition, apt-get install gcc. | ||
| 2. see https://github.com/mistay/AOS-Winter-2015/tree/selfie-master for how to get selfie up and running | ||
| 3. git clone repro from https://github.com/mistay/AOS-Winter-2015.git or, if pull request was accepted from | ||
| https://github.com/cksystemsteaching/AOS-Winter-2015.git | ||
| 4. change into cloned directory and do the following: | ||
|
|
||
| $ gcc -o selife selfie.c -fno-builtin | ||
| $ touch out | ||
| $ ./selfie -c < selfie.c | ||
| $ mv out selfie.mips1 | ||
| $ touch out | ||
| $ ./selfie -m 32 selfie.mips1 < linkedlist.c | ||
| mem 32MB | ||
| [OS] Terminated with 0 | ||
|
|
||
|
|
||
| To Run: | ||
| ======= | ||
| $ ./selfie -m 32 out | ||
| mem 32MB | ||
| d,c,b,a | ||
| d,b,a | ||
| done[OS] Terminated with 6 | ||
| $ | ||
|
|
||
| Interpretation and Explanation of what happened | ||
| =============================================== | ||
| First, linkedlist.c creates some arbitrary elements: | ||
|
|
||
| ... | ||
| head = create(0, 'a'); | ||
| head = create(head, 'b'); | ||
| toberemoved = create(head, 'c'); | ||
| ... | ||
|
|
||
| Then, the resulted list is printed to stdout: | ||
|
|
||
| d,c,b,a | ||
|
|
||
| Now, one element is removed: | ||
|
|
||
| ... | ||
| remove(head, toberemoved); | ||
| ... | ||
|
|
||
| The resulting list is printed again: | ||
| d,b,a | ||
|
|
||
|
|
||
| Some fixed chars are printed (this is an easter-egg styled 'hello world'): | ||
| done | ||
|
|
||
| And the application exits with exit code 6: just to clarify this application exits (and not the emulator). | ||
| Terminated with 6 | ||
|
|
||
|
|
||
| Result | ||
| ====== | ||
| [OK] must be implemented in C* | ||
| [OK] must compile with selfie | ||
| [OK] must run on selfie | ||
| [OK alloc() ] the list must be dynamically allocated | ||
| [OK, alloc() ] every node must be dynamically allocated | ||
| [OK, create() ] inserting nodes to the list and removing nodes from the list | ||
| [OK, printll()] list iteration | ||
| [NG] Bonus: sort the list. Any way you like | ||
| [OK, Oct 14] Deadline: Oct 15, end of day | ||
|
|
||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| //erzeugt listenelement | ||
| int* create(int* next, int data) { | ||
| int* s; | ||
| s = (int*)malloc( 2 * 4 ); | ||
|
|
||
| // next == 0 entspricht dem letzten element, ansonsten pointer aufs naechste | ||
| *(s+0) = next; | ||
|
|
||
| // payload, daten kommen hier rein, zB 'a' | ||
| *(s+1) = data; | ||
|
|
||
| return s; | ||
| } | ||
|
|
||
| // entfernt element von liste | ||
| // sucht element in liste rekursiv | ||
| void remove(int* head, int* element) { | ||
| int* next; | ||
| next = *(head+0); | ||
|
|
||
| if (next == element) { | ||
| // found, remove element. memleak todo: free next element's mem but not impl' yet in c*c | ||
| *(head + 0) = *(next + 0); | ||
| return; | ||
| } | ||
|
|
||
| if ((int)next == 0 ) { | ||
| // abbruchbedinung: das letzte element wurde gefunden, der next pointer zeigt auf (int)0 | ||
| return; | ||
| } | ||
| remove(next,element); | ||
|
|
||
|
|
||
| } | ||
|
|
||
| // gibt liste auf konsole aus, zB a,b,c, | ||
| // ruft sich dabei selbst rekursiv fuer alle elemente auf und bricht bei letztem element ab | ||
| void printll( int* element) { | ||
| int* next; | ||
| putchar(*(element + 1)); | ||
|
|
||
| next = *(element+0); | ||
| if ((int)next == 0 ) { | ||
| // abbruchbedinung: das letzte element wurde gefunden, der next pointer zeigt auf (int)0 | ||
| putchar(10); // newline (at least under *nix) | ||
| return; | ||
| } | ||
| putchar(','); | ||
| printll(next); | ||
| } | ||
|
|
||
| int main() { | ||
| int* head; | ||
| int* toberemoved; | ||
| head = create(0, 'a'); | ||
| head = create(head, 'b'); | ||
| toberemoved = create(head, 'c'); | ||
| head = toberemoved; | ||
| head = create(head, 'd'); | ||
| printll(head); | ||
|
|
||
| remove(head, toberemoved); | ||
|
|
||
| printll(head); | ||
|
|
||
| putchar('d'); | ||
| putchar('o'); | ||
| putchar('n'); | ||
| putchar('e'); | ||
| exit(6); | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the advantage of recursion in this case? The recursion parameter (next) is, in fact, an iterator. I'm not saying recursion is wrong here... But what is the advantage of recursion instead of iteration?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's just a little easier to read and (thus) more "elegant" - but: of course you can iterate through the list.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Be careful with metrics like "easier to read". They are highly subjective and therefore hard to compare. The actual reason why recursion is more elegant here is the list itself. A linked list is a recursive data type. Nice solution!