[英]ARM assembly pointers to pointers?
Suppose I am given as input to a function foo
some pointer *pL
that points to a pointer to a struct that has a pointer field next in it. 假设我给函数
foo
某些指针*pL
作为输入,该指针*pL
指向结构的指针,该结构的下一个指针字段存在。 I know this is weird, but all I want to implement in assembly is the line of code with the ** around it: 我知道这很奇怪,但是我想在汇编中实现的只是带有**的代码行:
typedef struct CELL *LIST;
struct CELL {
int element;
LIST next;
};
void foo(LIST *pL){
**(*pL)->next = NULL;**
}
How do I implement this in ARM assembly? 如何在ARM汇编中实现这一点? The issue comes from having nested startements when I want to store such as:
问题来自于我想存储诸如以下内容的嵌套实例:
.irrelevant header junk
foo:
MOV R1, #0
STR R1, [[R0,#0],#4] @This is gibberish, but [R0,#0] is to dereference and the #4 is to offeset that.
The sequence would be similar to: 顺序将类似于:
... ; r0 = LIST *pL = CELL **ppC (ptr2ptr2cell)
ldr r0,[r0] ; r0 = CELL *pC (ptr2cell)
mov r1,#0 ; r1 = NULL
str r1,[r0,#4] ; (*pL)->next = pC->next = (*pC).next = NULL
The correct sequence would be (assuming ARM ABI and LIST *pL
is in R0), 正确的顺序是(假设ARM ABI和
LIST *pL
位于R0中),
.global foo
foo:
ldr r0, [r0] # get *pL to R0
mov r1, #0 # set R1 to zero.
str r1, [r0, #4] # set (*pL)->List = NULL;
bx lr # return
You can swap the first two assembler statements, but it is generally better to interleave ALU with load/store for performance. 您可以交换前两个汇编程序语句,但是通常最好将ALU与load / store交错以提高性能。 With the ARM ABI, you can use R0-R3 without saving.
使用ARM ABI,无需保存即可使用R0-R3。
foo()
above should be callable from 'C' with most ARM compilers. 上面的
foo()
应该可以在大多数ARM编译器中从'C'调用。
The 'C' might be simplified to, “ C”可能会简化为
void foo(struct CELL **pL)
{
(*pL)->next = NULL;
}
if I understand correctly. 如果我理解正确的话。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.