CS208 Introduction to Computer Systems Friday, 15 May 2026 + exam prep + shell questions so far + redirection 1: > and < - printf = write(stdout) = write(1,...) - scanf = read(stdin) + redirection 2: | - command-line pipe purpose (and "Unix philosophy") - in C and the OS, what is a pipe? + who should do the second fork? - preemptive multitasking - "inodes" -- how Unix mostly stores files ===== Exam 2 prep ===== + Wednesday, May 20 + 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? + C structs - see the linked list in memory.c + x86-64 assembly language - What do these instructions do? (Check out Dive Into Systems) - mov, test, cmp, jmp, add, sub, mul, lea - call, ret - conditional jumps generally (don't need to memorize them) - relationship with ZF and SF - je - jump if ZF=1 - jne - jump if ZF=0 - jle - jump if SF=1 or ZF=1 ... - 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 mapped to 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)?