什么!在ARM组装中扮演角色? [英] What does the ! character do in ARM assembly?
问题描述
#include <stdio.h>
void fun();
int main()
{
int a = 10;
fun();
return 0;
}
void fun()
{
int a = 5;
}
汇编代码.
000103e4 <main>:
103e4: e52db008 str fp, [sp, #-8]!
103e8: e58de004 str lr, [sp, #4]
103ec: e28db004 add fp, sp, #4
103f0: e24dd008 sub sp, sp, #8
103f4: e3a0300a mov r3, #10
103f8: e50b3008 str r3, [fp, #-8]
103fc: eb000005 bl 10418 <fun>
10400: e3a03000 mov r3, #0
10404: e1a00003 mov r0, r3
10408: e24bd004 sub sp, fp, #4
1040c: e59db000 ldr fp, [sp]
10410: e28dd004 add sp, sp, #4
10414: e49df004 pop {pc} ; (ldr pc, [sp], #4)
00010418 <fun>:
10418: e52db004 push {fp} ; (str fp, [sp, #-4]!)
1041c: e28db000 add fp, sp, #0
10420: e24dd00c sub sp, sp, #12
10424: e3a03005 mov r3, #5
10428: e50b3008 str r3, [fp, #-8]
1042c: e1a00000 nop ; (mov r0, r0)
10430: e24bd000 sub sp, fp, #0
10434: e49db004 pop {fp} ; (ldr fp, [sp], #4)
10438: e12fff1e bx lr
在上面的汇编代码中 103e4:e52db008 str fp,[sp,#-8]!
In a above assembly code 103e4: e52db008 str fp, [sp, #-8]!
我是汇编语言的新手. 为什么 '!'已经被用了什么目的.
I am new to assembly language. why '!' has been used what is the purpose.
推荐答案
ARM汇编代码中的!
表示地址寄存器已更新. (这非常令人兴奋!)在str fp, [sp, #-8]!
中,将<8>添加到sp
,然后将fp
的内容存储在sp
中的新地址处.如果!
不存在,则fp
仍将存储在同一地址,但sp
不会被更新.
That !
in ARM assembly code means the address register is updated. (It is very exciting!) In str fp, [sp, #-8]!
, −8 is added to sp
, and then the contents of fp
are stored at the new address in sp
. If the !
were not present, fp
would still be stored at the same address, but sp
would not be updated.
有一条相应的指令,您可以在代码ldr fp, [sp], #4
的其他地方看到.以这种形式,fp
的内容存储在sp
中的地址,然后将4添加到sp
.
There is a corresponding instruction which you see elsewhere in the code, ldr fp, [sp], #4
. In this form, the contents of fp
are stored at the address in sp
, and then 4 is added to sp
.
第一种形式通常用于将事物压入堆栈:递减堆栈指针以为堆栈中的新事物腾出空间,然后写入该值.第二种形式用于弹出:读取堆栈上的值,然后递增堆栈指针,从而有效地从堆栈的活动部分中删除空间.
The first form is commonly used for pushing things onto the stack: The stack pointer is decremented to make room for new things on the stack, and then the value is written. The second form is used for popping: The value on the stack is read, and then the stack pointer is incremented, effectively removing the space from the live part of the stack.
它们也可以用于遍历数组,加载或存储元素以及移动指针,而无需单独的指令来加载/存储和更改指针.
They can also be used to iterate through an array, loading or storing elements and moving the pointer without needing separate instructions for loading/storing and changing the pointer.
这篇关于什么!在ARM组装中扮演角色?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!