CS208 Introduction to Computer Systems Wednesday, 16 October 2024 ----- TO FIND THIS DOCUMENT: - search online for "Jeff Ondich" - go to my homepage - click on the link for this course (CS208 Bridger's section) - click on Class Notes ----- + Today - if/else and loops: rip, jumps, cmp, test - calling functions: the system stack, rsp, push, pop, call, ret (and what the heck is rbp?) - your questions about the puzzles + Recap - Architecture: Registers + Memory - Sizes and names of registers rax (64 bits), eax (rightmost 32 bits of rax), ax (rightmost 16), al (rightmost 8) - Conventional register uses - rax/eax -- return value - rdi/edi -- first parameter of a function - rsi/esi -- second parameter of a function - [see Tanya's diagram] - Simple instructions - mov, add, sub - suffixes q (64 bits), l (32), w (16), b (8) - The weird lea instruction - lea (%rax, %rbx), %rcx -- rcx = rax + rbx - lea (%rax, %rbx, 4), %rcx -- rcx = rax + 4*rbx - lea 5(%rax, %rbx), %rcx -- rcx = rax + rbx + 5 - lea 5(%rax, %rbx, 4), %rcx -- rcx = rax + 4*rbx + 5 + Playing with Compiler Explorer - Settings (-Og flag; *not* Intel syntax; C, not C++) - Write a function int f(int a, int b) that does: return a + b What does the corresponding assembly look like? - Try some more return a * b return 5 * a + 9 * b - 50 try other formulas - Some of the instructions you might see - mov - add - leal - sub - ret - ... + History: Intel instruction set 1971: 4004 1970s-1980s: 8008, 8080, 8086 8-bit registers registers named a, b, c, etc. 1975: AMD cloned the 8080 1982: 80186, 80286 16-bit registers registers named ax, bx, cx, etc. (x = "extended") 1985: 80386 32-bit registers registers named eax, ebx, ecx, etc. (e = "extended", x = "extended") this language is called "x86" 1991: AMD vs. Intel monopoly lawsuit 1999: x86-64 (also known as x64) 64-bit registers: rax, rbx, etc. (r = register) + Instruction-name weirdness movq $3, %rax -- the q and the rax both say "64 bits" movl $3, %eax -- the l and the eax both say "32 bits" movw $3, %ax -- the w and the ax both say "16 bits" movb $3, %al -- the b and the al both say "8 bits"