CS208 Introduction to Computer Systems Wednesday, 29 April 2026 + questions + advice: step through the code manually + cmp, test, and jxx - EFLAGS: ZF="was the result 0?", SF="was the result negative?" - e.g., what does ADDL do to ZF and SF? - cmp R1, R2 --> R2 - R1 and set flags and some JXX's - test A, B --> A & B and set flags - test A, A --> A & A and set flags - je, jne, jg, jge, jl, jle,... + stack frames, call, and ret + addressing modes - %rcx - $0x2C - (%rsp) - (%rbx, %rcx, 4) - (%rbx, %rcx, 1) vs. (%rbx, %rcx) - 0x80(%rsp, %rcx, 4) - ... + what the heck is LEA for? + things to try with Compiler Explorer - https://godbolt.org/ - Let's do some experiments - what does simple arithmetic (+, -, *, /, %, |, ^, &, ~) look like? - what does an if-else look like? - what does a loop look like? + what's going on with... - puzzle2: pushq rbx, popq rbx (similar in puzzle4) - puzzle3: testq, sete, testq, sete, orb, je - puzzle4: subq $8, %rsp ... addq $8, %rsp - puzzle5: leal (%rcx,%rax), %esi - puzzle6: - movslq %edx, %rax salq $2, %rax movl -4(%rdi,%rax), %ecx - all those jumps - movl %r8d, (%rdi,%rdx,4) == void f(int *a, int n, int filler) { if (a != 0) { for (int k = 0; k < n; k++) { a[k] = filler; } } } int g(int b, int n) { int result = 1; for (int k = 1; k < n; k++) { result = result * b; } return result; }