0000000000000000 <main>: 0: push rbp 1: mov rbp,rsp 4: mov DWORD PTR [rbp-0xc],0x1 b: mov DWORD PTR [rbp-0x8],0x2 12: mov eax,DWORD PTR [rbp-0xc] 15: cdq 16: idiv DWORD PTR [rbp-0x8] 19: mov DWORD PTR [rbp-0x4],eax 1c: mov eax,0x0 21: pop rbp 22: ret
Here, the first two assembly instructions are part of the function prologue that is called every time a function is called. The RBP register points to the base of the stack and the local variables are referenced using the RBP register.
We are assigning 0x1 to the local variable a referenced by [RBP – 0xc] and 0x2 to the local variable b referenced by [RBP – 0x8].
After that, we are moving the content of the variable referenced by [RBP – 0xc] to the EAX register. Now, we are using the CDQ instruction to sign-extend the content of the EAX register so that the value of the EAX register is stored in EDX:EAX register. Please note that we are using integers in the C code that are 32 bits in length and hence, we are using EDX and EAX registers.
Now, we are using the idiv instruction to divide the content of EDX:EAX registers by the local variable b referenced by [RBP – 0x8]. After the division operation, the quotient will be stored in the EAX register and the remainder will be stored in the EDX register.
So, we are now moving the quotient or the content of the EAX register to the local variable c referenced by [RBP – 0x4].
The function now returns 0x0 through the EAX register and then, the function epilogue instructions are executed.






0 Comments