CS208 Introduction to Computer Systems Friday, 17 October 2025 + More asm puzzle guidance - (general principle: meta-analysis is good; try to put yourself in the prof's shoes) - (general principle: partial credit is good) - rax/eax/ax/al/ah; etc. (see Stanford summary doc) - recap of general approach - parentheses & pointers - parentheses, arithmetic, & arrays - lea instruction - C switch statement + register names - History of assembly languages - first programs required plugging in wires (mid-40s) - that was sad, so people came up with machine language that could be stored on punch cards/tapes instructions were sequences of bits - that was also sad, so people came up with synonyms for machine language instructions and programs to translate between the synonyms and the machine lang. those synonyms were the first assembly languages (late 40s, early 50s) - high-level languages with compilers and interpreters (50s, 60s, 70s,...) - about 1970, people were talking "put a whole computer on a chip"; Intel 4004, with 4-bit registers - mid-70s: Intel 8008, 8080: 8-bit registers register names: a, b, c, d, etc. - 1978: Intel 8086, 16-bit registers register names: ax, bx, cx, etc. ("x-tended") - Intel 80186, 80286...16-bit - Intel 80386 (late 80s): 32-bit registers register names: eax, ebx, ecx, etc. ("ex-tended") - Intel ...80686? first 64-bit chips register names: rax, rbx, rcx,... rax - 64 bits eax - lower order 32 bits of rax ax - lower order 16 bits of rax al - lower order 8 bits of rax (ah - second lowest order 8 bits of rax) + recap of general approach - find the parameters and identify their sizes rdi, rsi, rdx, rcx,... (use meta-analysis to guess C types) - find the return value and identify its size rax, eax, etc. - draw a picture and do a walk-through with some concrete parameter values - ... + parentheses & pointers (%rdi) = the thing pointed to by rdi + parentheses, arithmetic, & arrays (%rdi,%rbx) -- add %rdi to %rbx and use that sum as a pointer to go get the thing it points to (%rdi,%rbx,4) -- compute a new pointer %rdi + 4*%rbx and then go get what it points to (%rdi,%rbx,1) -- %rdi + 1*%rbx which is the same as (%rdi,%rbx) -8(%rdi,%rbx,4) -- %rdi + 4*%rbx - 8 -8(%rdi,%rbx) -- %rdi + %rbx - 8 -8(%rdi) -- %rdi - 8 Huh?? Answer: array indexing + lea instruction Does the computation (e.g., %rdi + %rbx*4) and then stores that in the destination register function1: testq %rdi, %rdi je .L6 movl $0, %eax jmp .L2 .L6: movl $0, %eax ret .L4: addl $1, %eax addq $1, %rdi .L2: cmpb $0, (%rdi) jne .L4 ret Parameter(s): %rdi, no %rsi suggests 1 8-byte parameter in rdi guess: type is char * Return type: seems to be in %eax so 32-bits, so probably int int function1(char *p) { int retval = 0; ... return retval; }