CS208 Introduction to Computer Systems Friday, 19 May 2023 + How would you answer these questions? - Suppose you do this - fork() - parent calls fgets - child calls fgets - user types something What happens? - What if you fork() once and call wait() twice? - Suppose you capture SIGINT. How can your program be killed? - ...other questions you wonder about?... + Next up - Back to assembly language: buffer overflow assignment (posted today) - Takehome final (handed out next Friday) - Network programming - Assembling all these pieces into a story of how computers work + Machine language thought experiment MOV $0x7, %eax RETQ CALLQ some_function_address ADD 0x4(%rsp,%rbx,8), %r8 ... Pretend - every instruction takes up 8 bytes Goal - come up with a scheme for representing the instructions above (and others) as 8-byte sequences Try this - one byte says "this is MOV" or "this is TEST" - MOV $0x7, %eax -- indicate that the first operand is immediate, value 7 so...second byte indicates addressing modes for both operands (4 bits apiece) later bytes, meaning depends on addressing mode ... + Machine language in real life gcc -o something -g -O1 -Wall -Werror something.c objdump -d something > something.d + Reminders on how functions get called (callq, retq, rsp, rip)