label definitoin mov eax, [ebx] Move the 4 bytes in memory at the address contained in EBX into EAX mov [var], ebx Move the contents of EBX into the 4 bytes at memory address var. mov eax, [esi-4] Move 4 bytes at memory address ESI + (-4) into EAX mov [esi+eax], cl Move the contents of CL into the byte at address ESI+EAX Data movement instructions label definitoin push eax push eax on the stack push [var] push the 4 bytes at address var onto the stack pop edi pop the top element of the stack into EDI. pop [ebx] pop the top element of the stack into memory at the four bytes starting at location EBX. Data movement instructions lea — Load effective address label definitoin lea edi, [ebx+4*esi] the quantity EBX+4*ESI is placed in EDI lea eax, [var] the value in var is placed in EAX. lea eax, [val] the value val is placed in EAX Data movement instructions label definitoin inc <reg> 1. Increment inc <mem> 2. decrement dec <reg> dec <mem> INC COUNT 1. Increment the memory variable COUNT dec eax 2. subtract one from the contents of EAX.
add <reg>,<reg> 1. Add the content of the
add <reg>,<mem> add <mem>,<reg> add <reg>,<con> add <mem>,<con> add eax, 10 1. Perform ADD operation on the 2. EAX ← EAX + 10 add BYTE PTR [var], 10 1. add 10 to the single byte stored at memory address var Data movement instructions label definitoin imul Integer Multiplication imul eax, [var] 1. multiply the contents of EAX by the 32-bit contents of imul esi, edi, 25 the memory location var. Store the result in EAX. idiv Integer Division and, xor, not 1. Bitwise logical and, or and exclusive or 2. Bitwise Logical Not shl, shr Shift Left, Shift Right (2n) Control flow label definitoin jmp Jump flow jcondition Condition Jump je<label> 1. jump when equal jne<label> 2. jump when not equal jz<label> 3. jump when last result was zero jg, jge,jl,jle 4. jump greater than/greater equal to/less than less than equal to cmp Compare cmp <reg>,<reg> 1. Bitwise Logical Not cmp <reg>,<mem> cmp <mem>,<reg> cmp <reg>,<con> call, ret Subroutine call and return # y in %rdi, z in %rsi, x in $rax int f (){ addq %rdi, %rsi int x = y + z; movq %rax, %rdi return x; ret }
int main() { main:
int n=5, movl $5, %eax long fact = 1; movl $1, %ebx L1: cmpl $0, %eax int i = 0; je L2 imull %eax, %ebx for (int i = n; i > 0; i--){ decl %eax fact *= i; jmp L1 } L2: ret return 0; } int foo(){ main: return x+5; movl $10, %eax } call foo ret int main() { foo: foo(); addl $5, %eax return 0; ret } Registry • storage class in c • visibility and location of variable • variable from program in registry