[英]Call atoi (Assembler) printf (Assembler)
I'm practicing programming in Assembly, making code C. I don't understand the conversion of a parameter to an integer using atoi. 我正在组装中练习编程,编写代码C。我不理解使用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: 另外,我想知道对函数printf的调用是如何工作的,这是代码段:
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是存储在寄存器中的值
(%eax) is value in memory using the value stored in eax (%eax)是使用eax中存储的值在内存中的值
Eg movl 4, %eax
movl 4, %eax
This sets the value of eax to 4. 这会将eax的值设置为4。
The value of (%eax) is now whatever is located in memory at the address of 4. 现在(%eax)的值就是内存中地址4处的值。
movl (%eax), %eax ; move the value in memory of eax (value eax points to) to the address of register eax
movl %eax, (%esp) ; move the address of eax to the value in memory of esp (value that esp points to)
movl %edx, 4(%esp) ; move the address of edx to the value in memory of esp + 4
movl %eax, (%esp) ; move the address of eax to the value in memory of esp
The reason the first example of yours has just movl %eax, (%esp)
is because atoi only takes one argument. 您的第一个示例仅使用
movl %eax, (%esp)
的原因是因为atoi仅接受一个参数。
The second example uses movl %edx, 4(%esp)
because eax is already being used and printf takes two arguments. 第二个示例使用
movl %edx, 4(%esp)
因为已经使用了eax并且printf接受了两个参数。
The parenthesis are register-indirect addressing (think pointer-dereferencing). 括号是寄存器间接寻址(请考虑指针解引用)。
number(register)
means "add the offset number
before dereferencing". number(register)
表示“在取消引用之前添加偏移number
”。
On how to call other functions, see the calling conventions for your system. 有关如何调用其他函数的信息,请参见系统的调用约定 。 For x86-32, see this .
对于x86-32,请参阅此 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.