arm c代码分解混乱,

arm c代码分解混乱,,arm,inline-assembly,Arm,Inline Assembly,我有以下代码: struct inner{ uint32_t a; uint32_t b; }; struct outer{ struct inner *in; }; void test_func(struct outer *o) { printh(o->in->b); } printh simple以十六进制格式显示值。 代码符合以下标志-DSMP-marm-mcpu=cortex-a15 生成的程序集如下所示: f0001cc0 &l

我有以下代码:

    struct inner{
    uint32_t a;
    uint32_t b;
};

struct outer{
    struct inner *in;
};

void test_func(struct outer *o)
{
    printh(o->in->b);
}
printh simple以十六进制格式显示值。 代码符合以下标志-DSMP-marm-mcpu=cortex-a15

生成的程序集如下所示:

f0001cc0 <test_func>:
f0001cc0:       e92d4800        push    {fp, lr}
f0001cc4:       e28db004        add     fp, sp, #4
f0001cc8:       e24dd008        sub     sp, sp, #8
f0001ccc:       e50b0008        str     r0, [fp, #-8]
f0001cd0:       e51b3008        ldr     r3, [fp, #-8]
f0001cd4:       e5933000        ldr     r3, [r3]
f0001cd8:       e5933004        ldr     r3, [r3, #4]
f0001cdc:       e1a00003        mov     r0, r3
f0001ce0:       ebfffb04        bl      f00008f8 <printh>
f0001ce4:       e24bd004        sub     sp, fp, #4
f0001ce8:       e8bd8800        pop     {fp, pc}
因此,我得到一个数据中止。

f0001cc0:
f0001cc0 <test_func>:
f0001cc0:       e92d4800        push    {fp, lr}           ;\
f0001cc4:       e28db004        add     fp, sp, #4         ;> create stack frame
f0001cc8:       e24dd008        sub     sp, sp, #8         ;/
f0001ccc:       e50b0008        str     r0, [fp, #-8]      ; save first arg (o) in stack
f0001cd0:       e51b3008        ldr     r3, [fp, #-8]      ; load o
f0001cd4:       e5933000        ldr     r3, [r3]           ; load o->in
f0001cd8:       e5933004        ldr     r3, [r3, #4]       ; load o->in->b
f0001cdc:       e1a00003        mov     r0, r3             ; use as first arg to next fn
f0001ce0:       ebfffb04        bl      f00008f8 <printh>  ; call printh
f0001ce4:       e24bd004        sub     sp, fp, #4         ;\
f0001ce8:       e8bd8800        pop     {fp, pc}           ;/ destroy stack frame
f0001cc0:e92d4800推送{fp,lr}\ f0001cc4:e28db004添加fp,sp,#4;>创建堆栈帧 f0001cc8:e24dd008子sp,sp,#8/ f0001ccc:e50b0008 str r0[fp,#-8];保存堆栈中的第一个参数(o) f0001cd0:e51b3008 ldr r3[fp,#-8];装载 f0001cd4:e5933000 ldr r3,[r3];加载o->in f0001cd8:e5933004 ldr r3,[r3,#4];加载o->in->b f0001cdc:e1a00003 mov r0,r3;用作下一个fn的第一个参数 f0001ce0:ebfffb04 bl f00008f8;打电话给printh f0001ce4:e24bd004子sp,fp,#4\ f0001ce8:e8bd8800 pop{fp,pc};/破坏堆栈框架

上面的代码(显然没有经过优化编译)首先加载
o->in
,然后加载
o->in->b
o->in
在0处出现,这意味着您尚未为其分配内存。

ldr r3,[r3]
in
指针加载到
r3
,下一行使用该指针获取
in->b
。您还没有向我们展示如何设置传递给
test_func
的结构,这使得很难说问题出在哪里。您确定为
内部
外部
分配了内存吗?@PaulR这一定是内存访问冲突。
f0001cc0 <test_func>:
f0001cc0:       e92d4800        push    {fp, lr}           ;\
f0001cc4:       e28db004        add     fp, sp, #4         ;> create stack frame
f0001cc8:       e24dd008        sub     sp, sp, #8         ;/
f0001ccc:       e50b0008        str     r0, [fp, #-8]      ; save first arg (o) in stack
f0001cd0:       e51b3008        ldr     r3, [fp, #-8]      ; load o
f0001cd4:       e5933000        ldr     r3, [r3]           ; load o->in
f0001cd8:       e5933004        ldr     r3, [r3, #4]       ; load o->in->b
f0001cdc:       e1a00003        mov     r0, r3             ; use as first arg to next fn
f0001ce0:       ebfffb04        bl      f00008f8 <printh>  ; call printh
f0001ce4:       e24bd004        sub     sp, fp, #4         ;\
f0001ce8:       e8bd8800        pop     {fp, pc}           ;/ destroy stack frame