CS208 Introduction to Computer Systems Wednesday, 15 October 2025 + Exam - Median 33.5/43 40-43: 3 30-39.5: 9 20-29.5: 5 10-19.5: 5 - Learning checkpoint - Time - Asking questions - Asking for different kinds of help #9 void remove_last_token(char **tokens, int *tokens_count) { // core of this function free(tokens[*tokens_count - 1]); tokens[*tokens_count - 1] = NULL; // OK, but not necessary *tokens_count--; } ---- + What's in registers eax, ebx, rax, rbx after this? movl $5, %ebx movl $4, %eax addl %ebx, %eax + Mini-history - AT&T / Bell Labs developed this instruction set (Unix tools like gcc use AT&T syntax) - Intel also developed this instruction set Notations are different + Homework advice - Figure out which parameters the function uses rdi, rsi, rdx, rcx,... - Figure out whether there's a return value, and how big it is - Draw a picture and step through the code with some value for the parameter(s) + puzzle0 - Function parameters %edi is present, %esi/%rsi is not so this looks like a 1-parameter function looks like probably an int, because %edi is 32 bits Note: also, %edi is used without being initialized which is what happens with parameters - Return value Does eax or rax or ax ... get a value? Yes: eax gets a value, and it's 32 bits - Let's try function1(5) testl %edi, %edi -- bitwise AND %edi with %edi and remember result (5) js - jump if the result of the test/cmp was negative execute movl, testl, js, ret i.e. label L2 then L2 ...eax ends up containing -5... - Let's try function1(-5) execute movl, testl, js, negl, jmp, ret i.e. labels: L3, then L2 ...eax ends up containing 5... // looks like absolute value int function1(int x) { }