Peter Mawhorter
8(%rdi, %rsi, 4)
scanfscanf
converts text into other types accordingly
%c, integers with
%d, floats with %f, and strings with
%s.scanfscanf and related functionsscanfscanf_s requires arguments to specify buffer sizes, but
is NOT available in C99 (which we’re using in this class)Explorer
link (look at %ebx)
%rbx, %rsp, %rbp, plus
%r12-15%rbp%rbp-4(%rbp) a lotpush → Move stack pointer %rsp down &
store valuepop → Load value & move stack pointer
%rsp upcall → Move %rsp down, store return
address, and jumpret → Load return address into %rip and
move %rsp upleave → Copies %rbp into %rsp
and then pops into %rbpsub, mov, etc. (Anything that stores to
%rsp directly)| Assembly code | Equivalent | Comments |
|---|---|---|
push %rbx |
sub $8,%rspmov %rbx,(%rsp) |
Create slot & store |
pop %rbx |
mov (%rsp),%rbxadd $8,%rsp |
Load & relinquish slot |
call 0x401123 |
sub $8,%rspmov $0x405007,(%rsp) |
Create slot & store address of next instruction |
ret |
mov (%rsp),%ripadd $8,%rsp |
Load return address into %rip “instruction pointer”
register & relinquish slot |
Stack grows downwards
Starting state
push %rdi # 0x4353
push %rsi # 0xf0
pop %rax
%rsp and/or
push, etc.%rsp₀ points to first slot%rsp points to bottom
cs240 start x86