CS208 Introduction to Computer Systems Wednesday, 12 November 2025 + Exam 1 corrections - problems 7 and 8: you can try the code - problem 9 - error-checking, short-circuited || and && - * vs. [] void remove_last_token(char **tokens, int *tokens_count) { //if (tokens == NULL || tokens_count == NULL || *tokens_count <= 0) { if (tokens == NULL || *tokens_count <= 0 || tokens_count == NULL) { //the second one crashes of tokens_count == NULL return; } ... free(tokens[*tokens_count - 1]); //free(*tokens[*tokens_count - 1]); <-- WRONG (arg here is type char) ... } + Shell questions + Exam prep (see below) + Networking - clients - servers - protocols - TCP connections - the Unix command nc (also known as netcat) + Playing with tcp connections - nc - telnet - curl - python3 -m http.server PORT ===== Exam 2 prep ===== + Question types - Short answers: vocabulary, simple computations, etc. - Here's some C code; what happens? - Here are some register values Here's some asm code What are the register values now? - Write a little code - Explain why something is the way it is, or does what it does + Memory - writing bytes as hexadecimal integers - byte order - what happens if you interpret a pointer to an array of char as a pointer to an int or an array of ints? - how do * and & work in their various contexts in C? - what's the difference between these two? char *p = "moose"; char p[6] = "moose"; - what does malloc do? what's the meaning of its return value? - what does free do? what's its return value? [trick question] - under what conditions would you malloc a chunk of memory instead of just declaring a big enough array? + i86-64 assembly language - What do these instructions do? (Check out Dive Into Systems) - mov, test, cmp, jmp, add, sub, mul, lea - call, ret - je (same as jz) - jump if ZF=1 - jne (same as jnz) - jump if ZF=0 - jg - jump if > - jge - jump if >= - jl - jump if < - jle - jump if <= - what are the purposes of the various special registers? - eflags (especially the ZF and SF bits) - rip - rsp - rax - rdi, rsi, rdx, rcx, ... - sizes - rax vs. eax vs. ax vs. al - movq vs. movl vs. movw vs. movb - how do the addressing modes work? movl $1, %eax # immediate ($1) and register (%eax) movl $1, 0x604892 # direct (address is constant value) movl $1, (%rax) # indirect (address is in register %rax) movl $1, -24(%rbp) # indirect with displacement movl $1, 8(%rsp, %rdi, 4) # indirect with displacement and scaled-index movl $1, (%rax, %rcx, 8) # (special case scaled-index, displ assumed 0) movl $1, 0x8(, %rdx, 4) # (special case scaled-index, base assumed 0) movl $1, 0x4(%rax, %rcx) # (special case scaled-index, scale assumed 1) + C structures --> i86-64 - What does an if-else look like in i86-64? - What does a loop look like in i86-64? - How does function-calling work in i86-64? - How to interpret the output of "objdump -d compiled-code" + gdb - interpreting an "examine memory" printout - si vs. ni - x/s vs. x/10wx vs. x/10bx vs. x/10gx + processes in C and Unix - what is a process? - what does the Unix command ps do? - what's a file descriptor? - what file descriptors are pre-initialized when you create a new process? - what do these C functions do? - fork - execlp/execvp - wait - dup2 - open, read, write - what is the point of dup2? - what is a pipe (on the command line)? - what is a pipe (in C code)?