CS208 Introduction to Computer Systems Wednesday, 7 February 2024 + Today - Exam returned - Lots more assembly language + Exam - Stats Possible: 50 High score: 50 Median: 33.5 40s: 9 30s: 7 20s: 10 Other: 2 - Submit corrections by class time Monday - no extensions - submit only corrections, on fresh paper - submit stapled to original exam - final score = ((original score) + (corrected score)) / 2 - I'll send course grade status reports Monday or Tuesday after I grade the corrections - Quick run-through of major issues + Break + How to learn assembly language (0) Take notes. Try to remember patterns of code. Think! (1) Read assembly on its own. Ask: - where does this instruction get its data? - where does this instruction put its result? - how is the EFLAGS register affected? - what addressing modes does this instruction use? (2) Write tiny functions in Compiler Explorer - what does a very simple if-statement turn into? if(a > 0) - what does a more complex if condition turn into? if(a > b && b > 0) - what does an if-else turn into? - what does a simple loop turn into? int k=10; while(k > 0) { k = k - 3; } - what does a function call look like? - what does a simple index-based traversal of an array look like? char buffer[10] = "goat"; int length = 0; for (int k = 0; buffer[k] != '\0'; k++) { length++; } - what does a pointer-based traversal of the same array look like? for (char *p = buffer; *p != '\0'; p++) { length++; } + Hints for the homework - what kinds of structures would I want you to see? - get started on a puzzle - what registers are used without initialization? those are your function's parameters (in order, they're rdi, rsi, rdx, rcx,...) - identify familiar assembly structures if-conditions loops (somewhere, there's a jump that goes backwards) assignment statements ... - one puzzle function takes 3 parameters; the others all take 1 or 2 - two of the puzzle functions compute the same thing--one iteratively and one recursively - you can ask questions on Slack - intention: get you used to paying attention to the details in assembly code; you're gonna need that habit for multiple future assignments ====== // Returns the correct length, but destroys the list // and leaks memory by not freeing the individual nodes. int linked_list_length(linked_list *the_list) { int count = 0; while (the_list->head != NULL) { count++; the_list->head = the_list->head->next; } return count; } // Better int linked_list_length(linked_list *the_list) { int count = 0; node *current = the_list->head; while (current != NULL) { count++; current = current->next; } return count; }