I’m practicing programming in Assembly, making code C.
I don’t understand the conversion of a parameter to an integer using atoi.
Can someone explain to me how I as interpret the following code segment:
movl 12(%ebp), %eax ; move a parameter to %eax
addl $4, %eax ; add 4 bytes
movl (%eax), %eax ; magic things
movl %eax, (%esp) ; magic things
call atoi ; atoi call
movl %eax, 24(%esp) ; asign the result of a magic procedure to a new variable
I understand some instructions, but the magic procedures are a little bit ambiguous to me.
Also, I want to know how works the call to the function printf, this is the segment of the code:
movl $.LC1, %eax ; assing the string (%d\n) to %eax
movl 28(%esp), %edx ; move the value to print to %edx
movl %edx, 4(%esp) ; magic things
movl %eax, (%esp) ; magic things
call printf ; call to printf
Thanks in advance for the support.
%eax is the value stored in the register
(%eax) is value in memory using the value stored in eax
E.g.
movl 4, %eaxThis sets the value of eax to 4.
The value of (%eax) is now whatever is located in memory at the address of 4.
The reason the first example of yours has just
movl %eax, (%esp)is because atoi only takes one argument.The second example uses
movl %edx, 4(%esp)because eax is already being used and printf takes two arguments.