CS208 Introduction to Computer Systems Monday, 24 April 2023 + Which order of arguments? Intel vs. AT&T notation. Intel mov rax, rbx -- copies rbx into rax cmp rbx, rcx -- subtract rbx - rcx jg somewhere -- jump if result was > 0 (>=?) * AT&T mov %rax, %rbx -- copies rax into rbx cmp %rbx, %rcx -- subtract rcx - rbx jg somewhere -- jump if result was > 0 (>=?) + q, l, w, b movq -- copy a 64-bit quantity (rax) movl -- copy a 32-bit quantity (eax) movw -- copy a 16-bit quantity (ax) movb -- copy an 8-bit quantity (al, ah) + Addressing modes mov %eax, %ebx -- register & register mov $0x50, %ebx -- immediate & register mov (%rbx), %rax -- indirect & register rbx has an address in it go to that address, grab the 8-byte quantity you find there and copy it into rax i.e., rbx is being used as a pointer mov (%rbx), %eax same, but grab 4 bytes of data mov 0x12(%rbx), %rax -- indirect + offset & register rbx has an address go to (that address + 0x12) get the data, put it in rax mov (%rbx, %rcx, 1), %rax rbx has an address rcx is a counter/index go to (rbx + rcx*1) get the data, put it in rax mov 0x34(%rbx, %rcx, 1), %rax same, but (0x34 + rbx + rcx*1) mov (%rbx, %rcx, 4), %rax rbx has an address rcx is a counter/index go to (rbx + rcx*4) get the data, put it in rax mov 0x56(%rbx, %rcx, 4), %rax same, but (0x56 + rbx + rcx*1) mov (%rbx, %rcx), %rax same as (%rbx, %rcx, 1) mov 0x78(%rbx, %rcx), %rax same as 0x78(%rbx, %rcx, 1) + Special registers (much more on these later) rsp rip eflags + Some non-obvious-but-essential instructions cmp %rbx, %rcx -- compute %rcx - %rbx, set eflags accordingly test %rbx, %rcx lea + Try this at godbolt.org - What does a C loop look like in asm? - What does a C if/else look like? - What does a loop over an array look like? - Harder: explore function-calling